Skip to content

Commit

Permalink
Feature: configurable logging
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Mar 5, 2025
1 parent 0480360 commit 4854771
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mwdb/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class MWDBConfig(Config):
enable_debug_log = key(cast=intbool, required=False, default=False)
enable_brownout = key(cast=intbool, required=False, default=False)

log_level = key(cast=str, required=False, default=None)
log_config_file = key(cast=path, required=False, default=None)


@section("karton")
class KartonConfig(Config):
Expand Down
17 changes: 16 additions & 1 deletion mwdb/core/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import logging.config

from flask import g
from pythonjsonlogger import jsonlogger
Expand Down Expand Up @@ -53,7 +54,21 @@ def setup_logger():
handler.setFormatter(formatter)
handler.addFilter(ContextFilter())
logger.addHandler(handler)
logger.setLevel(logging.DEBUG if app_config.mwdb.enable_debug_log else logging.INFO)

if app_config.mwdb.log_level is not None:
log_level_mapping = logging.getLevelNamesMapping()
log_level = log_level_mapping[app_config.mwdb.log_level.upper()]
logger.setLevel(log_level)
else:
logger.setLevel(
logging.DEBUG if app_config.mwdb.enable_debug_log else logging.INFO
)

if app_config.mwdb.log_config_file is not None:
logging.config.fileConfig(
app_config.mwdb.log_config_file,
disable_existing_loggers=False,
)


def getLogger():
Expand Down

0 comments on commit 4854771

Please sign in to comment.