Add CI
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
"""
|
||||
Centralized Cloud Logging setup.
|
||||
Uses CloudLoggingHandler (background thread) so logging does not add latency
|
||||
"""Centralized Cloud Logging setup.
|
||||
|
||||
Uses CloudLoggingHandler (background thread) so logging does not add latency.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional, Dict, Literal
|
||||
from typing import Literal
|
||||
|
||||
import google.cloud.logging
|
||||
from google.cloud.logging.handlers import CloudLoggingHandler
|
||||
|
||||
from .config import get_config
|
||||
|
||||
|
||||
_eval_log: logging.Logger | None = None
|
||||
|
||||
|
||||
def _get_logger() -> logging.Logger:
|
||||
"""Get or create the singleton evaluation logger."""
|
||||
global _eval_log
|
||||
global _eval_log # noqa: PLW0603
|
||||
if _eval_log is not None:
|
||||
return _eval_log
|
||||
|
||||
@@ -33,7 +32,7 @@ def _get_logger() -> logging.Logger:
|
||||
handler = CloudLoggingHandler(client, name=cfg.log_name) # async transport
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(getattr(logging, cfg.log_level.upper()))
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001
|
||||
# Fallback to console if Cloud Logging is unavailable (local dev)
|
||||
logging.basicConfig(level=getattr(logging, cfg.log_level.upper()))
|
||||
logger = logging.getLogger(cfg.log_name)
|
||||
@@ -46,15 +45,23 @@ def _get_logger() -> logging.Logger:
|
||||
return logger
|
||||
|
||||
|
||||
def log_structured_entry(message: str, severity: Literal["INFO", "WARNING", "ERROR"], custom_log: Optional[Dict] = None) -> None:
|
||||
"""
|
||||
Emit a JSON-structured log row.
|
||||
def log_structured_entry(
|
||||
message: str,
|
||||
severity: Literal["INFO", "WARNING", "ERROR"],
|
||||
custom_log: dict | None = None,
|
||||
) -> None:
|
||||
"""Emit a JSON-structured log row.
|
||||
|
||||
Args:
|
||||
message: Short label for the row (e.g., "Final agent turn").
|
||||
severity: "INFO" | "WARNING" | "ERROR"
|
||||
custom_log: A dict with your structured payload.
|
||||
|
||||
"""
|
||||
level = getattr(logging, severity.upper(), logging.INFO)
|
||||
logger = _get_logger()
|
||||
logger.log(level, message, extra={"json_fields": {"message": message, "custom": custom_log or {}}})
|
||||
logger.log(
|
||||
level,
|
||||
message,
|
||||
extra={"json_fields": {"message": message, "custom": custom_log or {}}},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user