9eaefac385
- Page fills the viewport horizontally (drop the 780px cap). - Copy button on the Logs card → copies the console (clipboard API on localhost, textarea-execCommand fallback), with a brief "Copied" confirmation. - Silence httpx/httpcore/huggingface_hub/urllib3/filelock/uvicorn.access/ ultralytics to WARNING so the console shows agent activity (detector loads, job errors, autoscale moves) instead of per-request HF-download spam. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""In-memory log ring buffer so the control UI can show recent agent logs
|
|
(detector loads, job errors, autoscaler decisions, outage back-offs) without
|
|
needing `docker logs`. A bounded deque holds the last N formatted lines; a
|
|
logging.Handler appends to it; the UI polls /logs."""
|
|
import logging
|
|
from collections import deque
|
|
|
|
LINES: deque[str] = deque(maxlen=600)
|
|
|
|
|
|
class RingHandler(logging.Handler):
|
|
def emit(self, record: logging.LogRecord) -> None:
|
|
try:
|
|
LINES.append(self.format(record))
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
_installed = False
|
|
|
|
|
|
def install(level: int = logging.INFO) -> None:
|
|
"""Attach the ring handler to the root logger once. fc_agent module loggers
|
|
propagate to root, so their records land here."""
|
|
global _installed
|
|
if _installed:
|
|
return
|
|
_installed = True
|
|
h = RingHandler()
|
|
h.setFormatter(
|
|
logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s", "%H:%M:%S")
|
|
)
|
|
root = logging.getLogger()
|
|
root.addHandler(h)
|
|
if root.level == logging.NOTSET or root.level > level:
|
|
root.setLevel(level)
|
|
# Keep the buffer signal-rich: silence the chatty HTTP/download libs (every
|
|
# HF model fetch logs per-request) so the console shows agent activity —
|
|
# detector loads, job errors, autoscale moves — not request spam.
|
|
for noisy in (
|
|
"uvicorn.access", "ultralytics", "httpx", "httpcore",
|
|
"huggingface_hub", "urllib3", "filelock",
|
|
):
|
|
logging.getLogger(noisy).setLevel(logging.WARNING)
|