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

[Log] CLILogging.configure returns as early as possible #228

Merged
merged 1 commit into from
Jan 25, 2021
Merged
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
10 changes: 6 additions & 4 deletions knack/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ def configure(self, args):
:param args: The arguments from the command line
:type args: list
"""
root_logger = logging.getLogger()

if root_logger.handlers:
# handlers already configured
return
Comment on lines +129 to +133
Copy link
Member Author

Choose a reason for hiding this comment

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

When run in pytest environment, root_logger is already set by pytest. If we don't return here before cli_logger.propagate = False, cli_logger.propagate = False will take effect and intercepts all logs sent to cli_loggers.

With this change, all logs will be handled by pytest directly.


self.log_level = self._determine_log_level(args)
console_log_levels = self._get_console_log_levels()
console_log_formats = self._get_console_log_formats()

root_logger = logging.getLogger()
# Set the levels of the loggers to lowest level.
# Handlers can override by choosing a higher level.
root_logger.setLevel(logging.DEBUG)
Expand All @@ -140,9 +145,6 @@ def configure(self, args):
cli_logger.setLevel(logging.DEBUG)
cli_logger.propagate = False

if root_logger.handlers:
# handlers already configured
return
self._init_console_handlers(root_logger, cli_loggers, console_log_levels, console_log_formats)
if self.file_log_enabled:
self._init_logfile_handlers(root_logger, cli_loggers)
Expand Down