Skip to content

Commit

Permalink
fix: prevent duplicate keys in stdlib log messages (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin authored Dec 17, 2024
1 parent 9211187 commit 0ddfac4
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 387 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.8.2
rev: v0.8.3
hooks:
- id: ruff
args:
Expand Down
12 changes: 8 additions & 4 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ def _is_tty() -> bool:


_render_as_json = not _is_tty()
_structlog_processors = default_structlog_processors(as_json=_render_as_json)
_structlog_default_processors = default_structlog_processors(as_json=_render_as_json)
_structlog_default_processors.insert(1, structlog.processors.EventRenamer("message"))
_structlog_standard_lib_processors = default_structlog_standard_lib_processors(as_json=_render_as_json)
_structlog_standard_lib_processors.insert(1, structlog.processors.EventRenamer("message"))

if settings.app.OPENTELEMETRY_ENABLED:
_structlog_processors.insert(-1, logfire.StructlogProcessor())
_structlog_default_processors.insert(-1, logfire.StructlogProcessor())
log = StructlogConfig(
enable_middleware_logging=False,
structlog_logging_config=StructLoggingConfig(
log_exceptions="always",
processors=_structlog_processors,
processors=_structlog_default_processors,
logger_factory=default_logger_factory(as_json=_render_as_json),
standard_lib_logging_config=LoggingConfig(
root={"level": logging.getLevelName(settings.log.LEVEL), "handlers": ["queue_listener"]},
formatters={
"standard": {
"()": structlog.stdlib.ProcessorFormatter,
"processors": default_structlog_standard_lib_processors(as_json=_render_as_json),
"processors": _structlog_standard_lib_processors,
},
},
loggers={
Expand Down
Loading

0 comments on commit 0ddfac4

Please sign in to comment.