Skip to content

Commit

Permalink
Allowing unknown int log levels (#40)
Browse files Browse the repository at this point in the history
Although it's neat to validate all `int` log levels are registered with
the `logging` module, this falls flat for 3rd party logging frameworks
(e.g. `loguru`, see #28)
  • Loading branch information
etianen authored Jan 28, 2024
1 parent 64d0ead commit b1c2662
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 8 deletions.
2 changes: 0 additions & 2 deletions logot/_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
def validate_levelno(level: int | str) -> int:
# Handle `int` level.
if isinstance(level, int):
if logging.getLevelName(level).startswith("Level "):
raise ValueError(f"Unknown level: {level!r}")
return level
# Handle `str` level.
if isinstance(level, str):
Expand Down
6 changes: 0 additions & 6 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ def test_validate_levelno_int_pass() -> None:
assert validate_levelno(logging.INFO) == logging.INFO


def test_validate_levelno_int_fail() -> None:
with pytest.raises(ValueError) as ex:
validate_levelno(9999)
assert str(ex.value) == "Unknown level: 9999"


def test_validate_levelno_str_pass() -> None:
assert validate_levelno("INFO") == logging.INFO

Expand Down

0 comments on commit b1c2662

Please sign in to comment.