Skip to content

Commit

Permalink
contrib.logging: inherit handler level in redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
kingarrrt committed Feb 1, 2023
1 parent 6791e8c commit 3fd948e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/tests_contrib_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ def test_should_inherit_console_logger_formatter(self):
with logging_redirect_tqdm(loggers=[logger]):
assert logger.handlers[0].formatter == formatter

def test_should_inherit_console_logger_level(self):
level = 99
logger = logging.Logger('test')
console_handler = logging.StreamHandler(sys.stderr)
console_handler.setLevel(level)
logger.handlers = [console_handler]
with logging_redirect_tqdm(loggers=[logger]):
assert logger.handlers[0].level == level

def test_should_not_remove_stream_handlers_not_for_stdout_or_stderr(self):
logger = logging.Logger('test')
stream_handler = logging.StreamHandler(StringIO())
Expand Down
1 change: 1 addition & 0 deletions tqdm/contrib/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def logging_redirect_tqdm(
orig_handler = _get_first_found_console_logging_handler(logger.handlers)
if orig_handler is not None:
tqdm_handler.setFormatter(orig_handler.formatter)
tqdm_handler.setLevel(orig_handler.level)
tqdm_handler.stream = orig_handler.stream
logger.handlers = [
handler for handler in logger.handlers
Expand Down

0 comments on commit 3fd948e

Please sign in to comment.