diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d2526..16a9f4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.2.0 (14.11.2023) + +### Changed + +- Default log level is now INFO + +### Added + +- Easy change of log level with `wandb_osh.set_log_level` + ## 1.1.2 (31.07.2023) ### Fixed diff --git a/pyproject.toml b/pyproject.toml index b5edb30..86f4f7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,5 +6,8 @@ xfail_strict = true [tool.ruff.isort] required-imports = ["from __future__ import annotations"] +[tool.ruff] +ignore-init-module-imports = true + [tool.pycln] all = true diff --git a/src/wandb_osh/__init__.py b/src/wandb_osh/__init__.py index 0e057a5..0d94e5c 100644 --- a/src/wandb_osh/__init__.py +++ b/src/wandb_osh/__init__.py @@ -6,3 +6,9 @@ from importlib_metadata import version # type: ignore __version__ = version("wandb_osh") + + +from wandb_osh.util.log import set_log_level + + +__all__ = ["__version__", "set_log_level"] diff --git a/src/wandb_osh/util/log.py b/src/wandb_osh/util/log.py index e9b06da..d554f12 100644 --- a/src/wandb_osh/util/log.py +++ b/src/wandb_osh/util/log.py @@ -5,7 +5,7 @@ import colorlog -LOG_DEFAULT_LEVEL = logging.DEBUG +LOG_DEFAULT_LEVEL = logging.INFO def get_logger(): @@ -42,4 +42,10 @@ def get_logger(): return _log +def set_log_level(level: str | int = LOG_DEFAULT_LEVEL) -> None: + """Sets the log level for the global logger.""" + logger = get_logger() + logger.setLevel(level) + + logger = get_logger() diff --git a/tests/test_cli.py b/tests/test_cli.py index 7586499..3315197 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3,9 +3,11 @@ import logging from wandb_osh.cli import main +from wandb_osh.util.log import set_log_level def test_cli(tmp_path, caplog): + set_log_level("DEBUG") with caplog.at_level(logging.INFO): main(argv=["--command-dir", str(tmp_path)]) assert "starting to watch" in caplog.text @@ -29,3 +31,4 @@ def test_cli(tmp_path, caplog): assert f"Syncing {target}" in caplog.text assert "wandb sync" in caplog.text assert "--sync-all" not in caplog.text + set_log_level() diff --git a/tests/test_log.py b/tests/test_log.py index 91e7054..2694d1b 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -3,6 +3,7 @@ import logging from wandb_osh.util.log import get_logger, logger +from wandb_osh import set_log_level def test_logger(): @@ -11,3 +12,9 @@ def test_logger(): def test_get_logger(): assert isinstance(get_logger(), logging.Logger) + + +def test_set_log_level(): + set_log_level("ERROR") + assert get_logger().level == logging.ERROR + set_log_level() diff --git a/tests/test_syncer.py b/tests/test_syncer.py index 739eb4a..c15af48 100644 --- a/tests/test_syncer.py +++ b/tests/test_syncer.py @@ -7,9 +7,11 @@ from pathlib import Path from wandb_osh.syncer import WandbSyncer +from wandb_osh.util.log import set_log_level def test_wandb_syncer(tmp_path, caplog): + set_log_level("DEBUG") tmp_path = Path(tmp_path) ws = WandbSyncer(tmp_path) target = tmp_path / "test" / "123" @@ -23,6 +25,7 @@ def test_wandb_syncer(tmp_path, caplog): with caplog.at_level(logging.DEBUG): ws.loop() assert f"Command would be: wandb sync . in {target.resolve()}" in caplog.text + set_log_level() def test_wandb_sync_timeout(tmp_path, caplog):