Skip to content

Commit

Permalink
Merge pull request #148 from bento-platform/feat/log-level-from-str
Browse files Browse the repository at this point in the history
feat: add logging submodule with config str to log level fn
  • Loading branch information
davidlougheed authored Nov 20, 2023
2 parents fc9bc31 + e1fb34c commit f1def70
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions bento_lib/logging.py
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)
9 changes: 9 additions & 0 deletions tests/test_logging.py
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

0 comments on commit f1def70

Please sign in to comment.