Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify set_global_logger_level use of contextmanager #418

Merged
merged 2 commits into from
May 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions qlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,16 @@ def filter(self, record):
return allow


@contextmanager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhupr Please keep the previous set_global_logger_level function and create a new contextmanager.
I think they are both very useful.
Besides, please add detailed docstrings about the feature.

Thanks

def set_global_logger_level(level: int):
_handler_level_map = {}
qlib_logger = logging.root.manager.loggerDict.get("qlib", None)
if qlib_logger is not None:
for _handler in qlib_logger.handlers:
_handler_level_map[_handler] = _handler.level
_handler.level = level
try:
yield
finally:
for _handler, _level in _handler_level_map.items():
_handler.level = _level