diff --git a/client/log.py b/client/log.py new file mode 100644 index 0000000..8a3532d --- /dev/null +++ b/client/log.py @@ -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)