feat: Structlog-Integration für strukturiertes Logging (closes #4)
This commit is contained in:
@@ -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))
|
||||
Reference in New Issue
Block a user