feat: Structlog-Integration für strukturiertes Logging (closes #4)

This commit is contained in:
hermes
2026-06-22 09:47:47 +00:00
parent 74c10b719b
commit fc464afaf5
2 changed files with 65 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Logging-Konfiguration mit structlog für strukturierte Logs."""
from __future__ import annotations
from typing import cast
import structlog
def setup_logging() -> None:
"""Konfiguriert strukturiertes Logging mit structlog."""
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.dev.ConsoleRenderer(),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
def get_logger(name: str) -> structlog.stdlib.BoundLogger:
"""Erstellt einen benannten Logger.
Args:
name: Logger-Name (üblicherweise __name__).
Returns:
Konfigurierter structlog-Logger.
"""
return cast(structlog.stdlib.BoundLogger, structlog.get_logger(name))