Plan 3: add client.log structured logger
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
"""Structured stdout logging suitable for journald capture."""
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
_CONFIGURED = False
|
||||||
|
|
||||||
|
|
||||||
|
def configure(level: str | int | None = None) -> None:
|
||||||
|
"""Configure root logging once. Safe to call multiple times."""
|
||||||
|
global _CONFIGURED
|
||||||
|
if _CONFIGURED:
|
||||||
|
return
|
||||||
|
if level is None:
|
||||||
|
level = os.environ.get("ASSISTANT_LOG_LEVEL", "INFO").upper()
|
||||||
|
logging.basicConfig(
|
||||||
|
level=level,
|
||||||
|
format="%(asctime)s %(levelname)-5s %(name)s %(message)s",
|
||||||
|
datefmt="%H:%M:%S",
|
||||||
|
stream=sys.stdout,
|
||||||
|
)
|
||||||
|
_CONFIGURED = True
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger(name: str) -> logging.Logger:
|
||||||
|
"""Return a logger named `name`; auto-configure on first call."""
|
||||||
|
configure()
|
||||||
|
return logging.getLogger(name)
|
||||||
Reference in New Issue
Block a user