Skip to content

Commit

Permalink
💥 Default log level to INFO; set_log_level (#75)
Browse files Browse the repository at this point in the history
Closes #74
Closes #73
  • Loading branch information
klieret committed Nov 14, 2023
1 parent 622ab1e commit ffa08db
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ wandb-osh -- --sync-all
You can start `wandb-osh` with `wandb-osh -- --sync-all` to always synchronize
all available runs.

> How can I suppress logging messages (e.g., warnings about the syncing not being fast enough)
```python3
import wandb_osh

# for wandb_osh.__version__ >= 1.2.0
wandb_osh.set_log_level("ERROR")
```

## 🧰 Development setup

```bash
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = wandb_osh
version = 1.1.2
version = 1.2.0
description = Trigger wandb offline syncs from a compute node without internet
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
6 changes: 6 additions & 0 deletions src/wandb_osh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 7 additions & 1 deletion src/wandb_osh/util/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import colorlog

LOG_DEFAULT_LEVEL = logging.DEBUG
LOG_DEFAULT_LEVEL = logging.INFO


def get_logger():
Expand Down Expand Up @@ -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()
3 changes: 3 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
7 changes: 7 additions & 0 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
3 changes: 3 additions & 0 deletions tests/test_syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down

0 comments on commit ffa08db

Please sign in to comment.