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

This commit is contained in:
Fernando Pérez-García 2022-03-07 10:11:47 +00:00 коммит произвёл GitHub
Родитель 501f3920c6
Коммит 6b62d8cbcd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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)
@ -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.