-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from bento-platform/feat/log-level-from-str
feat: add logging submodule with config str to log level fn
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import logging | ||
|
||
__all__ = [ | ||
"log_level_from_str", | ||
] | ||
|
||
|
||
log_level_str_to_log_level = { | ||
"debug": logging.DEBUG, | ||
"info": logging.INFO, | ||
"warning": logging.WARNING, | ||
"error": logging.ERROR, | ||
} | ||
|
||
|
||
def log_level_from_str(level: str, default: int = logging.INFO) -> int: | ||
return log_level_str_to_log_level.get(level.lower(), default) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import logging | ||
from bento_lib.logging import log_level_from_str | ||
|
||
|
||
def test_log_level_from_str(): | ||
assert log_level_from_str("DEBUG") == logging.DEBUG | ||
assert log_level_from_str("info") == logging.INFO | ||
assert log_level_from_str("asdf", default=logging.DEBUG) == logging.DEBUG | ||
assert log_level_from_str("asdf", default=logging.INFO) == logging.INFO |