Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Print out name of log level, not only the number #678

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ created.

### Added

- ([#678](https://github.com/microsoft/InnerEye-DeepLearning/pull/678)) Add function to get log level name and use it for logging.
- ([#666](https://github.com/microsoft/InnerEye-DeepLearning/pull/666)) Replace RadIO with TorchIO for patch-based inference.
- ([#643](https://github.com/microsoft/InnerEye-DeepLearning/pull/643)) Test for recovery of SSL job. Tracks learning rate and train
loss.
Expand Down
13 changes: 12 additions & 1 deletion InnerEye/Common/common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def logging_to_stdout(log_level: Union[int, str] = logging.INFO) -> None:
logging_stdout_handler = logging.StreamHandler(stream=sys.stdout)
_add_formatter(logging_stdout_handler)
logger.addHandler(logging_stdout_handler)
print(f"Setting logging level to {log_level}")
print(f"Setting logging level to {log_level} ({get_log_level_string(log_level)})")
logging_stdout_handler.setLevel(log_level)
logger.setLevel(log_level)

Expand All @@ -170,6 +170,17 @@ def standardize_log_level(log_level: Union[int, str]) -> int:
return log_level


def get_log_level_string(log_level: int) -> str:
"""
:param log_level: integer version of a log level, e.g. 20.
:return: string version of the level; throws an error if the level is not registered.
"""
valid_levels = list(logging._levelToName.keys())
if log_level not in valid_levels:
raise ValueError(f"Log level {log_level} is not valid. Possible values are: {valid_levels}")
return logging._levelToName[log_level]


def logging_to_file(file_path: Path) -> None:
"""
Instructs the Python logging libraries to start writing logs to the given file.
Expand Down