mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
Add retained chat and API request diagnostics
This commit is contained in:
31
backend/app/logging.py
Normal file
31
backend/app/logging.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""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,
|
||||
)
|
||||
Reference in New Issue
Block a user