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.
This commit is contained in:
Keith Edmunds 2021-06-06 10:50:40 +01:00
parent dbf0c27a09
commit e498457395
2 changed files with 15 additions and 3 deletions

View File

@ -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')

View File

@ -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):