diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 02cba20..07f2065 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,6 @@ +v1.0.12 +- Properly decode argument to number or string +- Make default level from CLI = None v1.0.11 - Set minimum requirement to python 3.8 v1.0.10 diff --git a/logistro/_api.py b/logistro/_api.py index 9985f04..7a3bff3 100644 --- a/logistro/_api.py +++ b/logistro/_api.py @@ -133,8 +133,11 @@ def betterConfig(**kwargs: Any) -> None: # noqa: N802 camel-case like logging implicit = kwargs.pop("implicit", False) # its implicitly called and we're already setup if not implicit or not logging.getLogger().handlers: - if "level" not in kwargs: - kwargs["level"] = cli_args.parsed.log.upper() + if "level" not in kwargs and cli_args.parsed.log: + if cli_args.parsed.log.isnumeric(): + kwargs["level"] = int(cli_args.parsed.log) + else: + kwargs["level"] = cli_args.parsed.log.upper() logging.basicConfig(**kwargs) coerce_logger(logging.getLogger()) betterConfig.__code__ = (lambda **_kwargs: None).__code__ @@ -144,7 +147,7 @@ def betterConfig(**kwargs: Any) -> None: # noqa: N802 camel-case like logging def getLogger(name: str | None = None) -> _LogistroLogger: # noqa: N802 camel-case like logging """Call `logging.getLogger()` but check `betterConfig()` first.""" betterConfig(implicit=True) - return cast(_LogistroLogger, logging.getLogger(name)) + return cast("_LogistroLogger", logging.getLogger(name)) _LoggerFilter = Callable[[logging.LogRecord, Dict[str, Any]], bool] diff --git a/logistro/_args.py b/logistro/_args.py index 1cecb66..26d6b1b 100644 --- a/logistro/_args.py +++ b/logistro/_args.py @@ -29,9 +29,10 @@ parser.add_argument( "--logistro-level", - default="WARNING", + default=None, + type=str, dest="log", - help="Set the logging level (default WARNING)", + help="Set the logging level (no default, fallback to system default)", ) # Get the Format diff --git a/pyproject.toml b/pyproject.toml index e1c2182..39e01e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,6 @@ ignore = [ "SIM105", # Too opionated (try-except-pass) "PT003", # scope="function" implied but I like readability "G004", # I like fstrings in my log - ] [tool.ruff.lint.per-file-ignores]