mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:28:47 +02:00
32 lines
1005 B
Python
32 lines
1005 B
Python
"""Structured, redacted application logging for container stdout."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from datetime import date, datetime
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
|
|
class _JSONEncoder(json.JSONEncoder):
|
|
def default(self, value: Any) -> Any:
|
|
if isinstance(value, (datetime, date)):
|
|
return value.isoformat()
|
|
if isinstance(value, Enum):
|
|
return value.value
|
|
return super().default(value)
|
|
|
|
|
|
def configure_structured_logging() -> None:
|
|
"""Reserved lifecycle hook for the structured stdout audit channel."""
|
|
|
|
|
|
def log_event(event: str, **fields: Any) -> None:
|
|
"""Write a single JSON line; callers must not pass credentials or bodies."""
|
|
# stdout is Docker's durable capture point. `flush=True` also makes this
|
|
# visible immediately in `docker compose logs` during an active SSE run.
|
|
print(
|
|
json.dumps({"event": event, **fields}, cls=_JSONEncoder, separators=(",", ":")),
|
|
flush=True,
|
|
)
|