diff --git a/README.md b/README.md index beac9ba..d22da6c 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,11 @@ adequately describes the associated data. All Bento channels are prefixed with `bento.`. +### `logging` + +`logging` contains helper functions for standardized Bento logging configuration +and formatting. + ### `responses` `responses` contains standardized error message-generating functions diff --git a/bento_lib/logging.py b/bento_lib/logging.py new file mode 100644 index 0000000..2e5d924 --- /dev/null +++ b/bento_lib/logging.py @@ -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) diff --git a/tests/test_logging.py b/tests/test_logging.py new file mode 100644 index 0000000..8598954 --- /dev/null +++ b/tests/test_logging.py @@ -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