update logger configuration

This commit is contained in:
春河晴
2025-06-11 15:48:59 +09:00
parent 7b4e7b94f8
commit 302240478c
4 changed files with 26 additions and 4 deletions

View File

@@ -1,7 +1,26 @@
import logging
from typing import Callable, Optional
import structlog
# TODO: customize the logger configuration as needed
# TODO: compress the log output
# TODO: output to a file with JSON format
structlog.configure(
processors=[
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False),
structlog.dev.ConsoleRenderer(),
],
wrapper_class=structlog.make_filtering_bound_logger(logging.NOTSET),
context_class=dict,
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=False,
)
raw_logger = structlog.get_logger()
binds: dict[str, Callable] = {}
@@ -12,5 +31,5 @@ def get_logger(name: Optional[str]):
return raw_logger
logger = binds.get(name)
if logger is None:
binds[name] = logger = structlog.get_logger(name).bind(name=name)
binds[name] = logger = structlog.get_logger(name).bind(logger_name=name)
return logger