From 8441f8badd621aa75009c192777f0ffef4d5e577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Berm=C3=BChler?= Date: Tue, 18 Jan 2022 18:23:23 +0100 Subject: [PATCH] Removed usage of logging.basicConfig logging.basicConfig will change the configuration of the root logger and not the configuration of your own library logger. Since parsedmarc is a library, it should keep its logging configuration to its own logger, such that the logging configuration of applications using this library are not affected. --- parsedmarc/__init__.py | 8 +++++--- parsedmarc/cli.py | 3 --- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index 75fc02a..5f8352e 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -38,12 +38,14 @@ from parsedmarc.utils import parse_email __version__ = "7.1.1" -logging.basicConfig( - format='%(levelname)8s:%(filename)s:%(lineno)d:' - '%(message)s', +formatter = logging.Formatter( + fmt='%(levelname)8s:%(filename)s:%(lineno)d:%(message)s', datefmt='%Y-%m-%d:%H:%M:%S') +handler = logging.StreamHandler() +handler.setFormatter(formatter) logger = logging.getLogger("parsedmarc") +logger.addHandler(handler) logger.debug("parsedmarc v{0}".format(__version__)) feedback_report_regex = re.compile(r"^([\w\-]+): (.+)$", re.MULTILINE) diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index 1418e80..441789f 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -578,14 +578,11 @@ def _main(): else: opts.syslog_port = 514 - logging.basicConfig(level=logging.WARNING) logger.setLevel(logging.WARNING) if opts.verbose: - logging.basicConfig(level=logging.INFO) logger.setLevel(logging.INFO) if opts.debug: - logging.basicConfig(level=logging.DEBUG) logger.setLevel(logging.DEBUG) if opts.log_file: fh = logging.FileHandler(opts.log_file)