Skip to content

Improve Logging Configuration: don't modify root logger #182

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

Merged
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
17 changes: 14 additions & 3 deletions pytest_mpl/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,22 @@ def __init__(self,
self._test_stats = None
self.return_value = {}

# https://stackoverflow.com/questions/51737378/how-should-i-log-in-my-pytest-plugin
# turn debug prints on only if "-vv" or more passed
# configure a separate logger for this pluggin which is independent
# of the options that are configured for pytest or for the code that
# is tested; turn debug prints on only if "-vv" or more passed
level = logging.DEBUG if config.option.verbose > 1 else logging.INFO
logging.basicConfig(level=level)
if config.option.log_cli_format is not None:
fmt = config.option.log_cli_format
else:
# use pytest's default fmt
fmt = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s"
formatter = logging.Formatter(fmt)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
self.logger = logging.getLogger('pytest-mpl')
self.logger.propagate = False
self.logger.setLevel(level)
self.logger.addHandler(handler)

def generate_filename(self, item):
"""
Expand Down