init
This commit is contained in:
40
backend/core/logging.py
Normal file
40
backend/core/logging.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Logging - 16 May 2025
|
||||
Dev - colored console
|
||||
Prod - structured JSON
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import logging, os, structlog
|
||||
from core.settings import LOG_LEVEL, ENV
|
||||
|
||||
def init_logging() -> None:
|
||||
log_level = getattr(logging, LOG_LEVEL.upper(), logging.INFO)
|
||||
|
||||
if ENV == "production":
|
||||
processors = [
|
||||
structlog.processors.TimeStamper(fmt="%Y-%m-%dT%H:%M:%S", utc=True),
|
||||
structlog.processors.add_log_level,
|
||||
_add_path,
|
||||
structlog.processors.JSONRenderer(),
|
||||
]
|
||||
else:
|
||||
|
||||
processors = [
|
||||
structlog.processors.TimeStamper(fmt="%H:%M:%S"),
|
||||
structlog.processors.add_log_level,
|
||||
structlog.dev.ConsoleRenderer(colors=True),
|
||||
]
|
||||
|
||||
structlog.configure(
|
||||
wrapper_class=structlog.make_filtering_bound_logger(log_level),
|
||||
processors=processors,
|
||||
)
|
||||
|
||||
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
|
||||
|
||||
def _add_path(_, __, event_dict):
|
||||
from quart import request
|
||||
if request:
|
||||
event_dict["path"] = request.path
|
||||
return event_dict
|
||||
|
||||
Reference in New Issue
Block a user