From 7c503b4a318a5a39317e37f6c06cfb362f7af95f Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Wed, 31 Jul 2019 09:40:36 +0300 Subject: [PATCH] provide a default logging configuration (fixes #987) --- cps/logger.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cps/logger.py b/cps/logger.py index 892dd252..54be25e7 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -95,13 +95,6 @@ def setup(log_file, log_level=None): Configure the logging output. May be called multiple times. ''' - # if debugging, start logging to stderr immediately - if os.environ.get('FLASK_DEBUG', None): - log_file = LOG_TO_STDERR - log_level = logging.DEBUG - - log_file = _absolute_log_file(log_file, DEFAULT_LOG_FILE) - log_level = log_level or DEFAULT_LOG_LEVEL logging.getLogger(__package__).setLevel(log_level) @@ -110,6 +103,8 @@ def setup(log_file, log_level=None): # avoid spamming the log with debug messages from libraries r.setLevel(log_level) + log_file = _absolute_log_file(log_file, DEFAULT_LOG_FILE) + previous_handler = r.handlers[0] if r.handlers else None if previous_handler: # if the log_file has not changed, don't create a new handler @@ -167,3 +162,7 @@ class StderrLogger(object): self.buffer += message except Exception: self.log.debug("Logging Error") + + +# default configuration, before application settngs are applied +setup(LOG_TO_STDERR, logging.DEBUG if os.environ.get('FLASK_DEBUG') else DEFAULT_LOG_LEVEL)