From 908e3f4907be499feb6e1dca32b2e44acdfc0544 Mon Sep 17 00:00:00 2001 From: Assistant builder Date: Thu, 11 Jun 2026 22:46:44 +0000 Subject: [PATCH] Plan 3: add client.log structured logger --- client/log.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 client/log.py 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)