Skip to content

Commit

Permalink
refactor: logging default config avoid to use dictConfig
Browse files Browse the repository at this point in the history
so it does not overwrite the default logging configuration
  • Loading branch information
azmeuk committed Jan 13, 2025
1 parent acb09f4 commit 19a2278
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions canaille/app/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from flask import has_request_context
from flask import request
from flask.logging import default_handler


class IPFilter(logging.Filter):
Expand Down Expand Up @@ -62,30 +63,18 @@ def setup_logging(app):
add_log_level(security_level_name, security_level)

if conf is None:
root_logger = logging.getLogger()
root_logger.setLevel(logging.WARNING)

log_level = "DEBUG" if app.debug else "INFO"
dictConfig(
{
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s] - %(ip)s - %(levelname)s in %(module)s: %(message)s",
}
},
"handlers": {
"wsgi": {
"class": "logging.StreamHandler",
"stream": "ext://flask.logging.wsgi_errors_stream",
"formatter": "default",
}
},
"root": {"level": log_level, "handlers": ["wsgi"]},
"loggers": {
"faker": {"level": "WARNING"},
"mail.log": {"level": "WARNING"},
},
"disable_existing_loggers": False,
}
formatter = logging.Formatter(
"[%(asctime)s] - %(ip)s - %(levelname)s in %(module)s: %(message)s"
)
handler = logging.StreamHandler(stream="ext://flask.logging.wsgi_errors_stream")
handler.setFormatter(formatter)
app.logger.setLevel(log_level)
app.logger.removeHandler(default_handler)
app.logger.addHandler(handler)

elif isinstance(conf, dict):
dictConfig(conf)
Expand Down

0 comments on commit 19a2278

Please sign in to comment.