From e4984573956aad3e67939dd91b5d60c38ff48a68 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 6 Jun 2021 10:50:40 +0100 Subject: [PATCH] Add option to force DEBUG message to stderr If the default log level for stderr is greater than DEBUG, DEBUG message won't be shown. The DEBUG(msg) function now takes an optional Boolean second parameter. If that is True, the DEBUG message is always sent to stderr. --- app/config.py | 2 +- app/log.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/config.py b/app/config.py index f8b21d0..1d8ee5a 100644 --- a/app/config.py +++ b/app/config.py @@ -20,7 +20,7 @@ class Config(object): ERRORS_TO = ['kae@midnighthax.com'] FADE_STEPS = 20 FADE_TIME = 3000 - LOG_LEVEL_STDERR = logging.DEBUG + LOG_LEVEL_STDERR = logging.INFO LOG_LEVEL_SYSLOG = logging.DEBUG LOG_NAME = "musicmuster" MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') diff --git a/app/log.py b/app/log.py index 510cf55..8fcb1a9 100644 --- a/app/log.py +++ b/app/log.py @@ -59,8 +59,20 @@ def log_uncaught_exceptions(ex_cls, ex, tb): sys.excepthook = log_uncaught_exceptions -def DEBUG(msg): - log.debug(msg) +def DEBUG(msg, force_stderr=False): + """ + Outupt a log message at level DEBUG. If force_stderr is True, + output this message to stderr regardless of default stderr level + setting. + """ + + if force_stderr: + old_level = stderr.level + stderr.setLevel(logging.DEBUG) + log.debug(msg) + stderr.setLevel(old_level) + else: + log.debug(msg) def EXCEPTION(msg):