From 97845186d160c12c978c17abbc01bf903fcc9ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Tue, 29 Jun 2021 14:06:23 +0200 Subject: [PATCH] Make logging opt-in --- sanity_html/logger.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sanity_html/logger.py b/sanity_html/logger.py index 8b2fe02..7d9ea67 100644 --- a/sanity_html/logger.py +++ b/sanity_html/logger.py @@ -1,12 +1,13 @@ +""" +Logging setup. + +The rest of the code gets the logger through this module rather than +`logging.getLogger` to make sure that it is configured. +""" import logging -import sys logger = logging.getLogger('sanity_html') -# Make logger output to stdout -logger.setLevel(logging.DEBUG) -handler = logging.StreamHandler(sys.stdout) -handler.setLevel(logging.DEBUG) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') -handler.setFormatter(formatter) -logger.addHandler(handler) +if not logger.handlers: # pragma: no cover + logger.setLevel(logging.WARNING) + logger.addHandler(logging.NullHandler())