forked from ChelseaKR/ceqa-preflight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobservability.py
More file actions
31 lines (22 loc) · 938 Bytes
/
Copy pathobservability.py
File metadata and controls
31 lines (22 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Minimal, opt-in operational logging that never emits package contents."""
from __future__ import annotations
import json
import logging
from typing import Any
LOGGER = logging.getLogger("ceqa_preflight")
def configure_logging(log_format: str) -> None:
"""Configure package-content-free operational logs on stderr."""
LOGGER.handlers.clear()
LOGGER.propagate = False
if log_format == "json":
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(message)s"))
LOGGER.addHandler(handler)
LOGGER.setLevel(logging.INFO)
else:
LOGGER.setLevel(logging.CRITICAL + 1)
def event(name: str, **fields: str | int | bool) -> None:
"""Emit a safe JSON event only when JSON logging is enabled."""
if LOGGER.isEnabledFor(logging.INFO):
payload: dict[str, Any] = {"event": name, **fields}
LOGGER.info(json.dumps(payload, sort_keys=True))