From 81375b5c9ccc5ca3161eb487aa81469d40ded221 Mon Sep 17 00:00:00 2001 From: Juho-Pekka Kuitunen Date: Fri, 7 Jan 2022 10:41:47 +0200 Subject: [PATCH] Surface Werkzeug and other internal logging to loguru at orig level (#1220) - With the previous logic all standard logging logs are downgraded to DEBUG5 regardless of their initial level. This will hide any fatal errors making debugging harder. - Since Werkzeug is quite chatty at INFO level, anything at INFO or above is still downgraded to DEBUG5. This maintains the current behavior for those log messages. --- mapadroid/utils/logging.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mapadroid/utils/logging.py b/mapadroid/utils/logging.py index 0bdcc9de6..013a8998b 100644 --- a/mapadroid/utils/logging.py +++ b/mapadroid/utils/logging.py @@ -295,7 +295,14 @@ def __init__(self, *args, **kwargs): def emit(self, record): with logger.contextualize(identifier=self.log_identifier): - logger.opt(depth=6, exception=record.exc_info).log("DEBUG5", record.getMessage()) + level = record.levelno + # Downgrade anything INFO and lower to DEBUG5 to match legacy behavior. + # Werkzeug is a bit too chatty at INFO level for it to be useful. + if level <= logging.INFO: + level = "DEBUG5" + else: + level = logging.getLevelName(level) + logger.opt(depth=6, exception=record.exc_info).log(level, record.getMessage()) # this is being used to change log level for gevent/Flask/Werkzeug