Initial commit: Javis project
This commit is contained in:
commit
435c645f36
164 files changed
+35279
No files matched your search
@@ -0,0 +1,46 @@
|
||||
"""Minimal stdlib logging helper (kept dependency-free from the javis package).
|
||||
|
||||
Logs go to stderr and to a rotating file under ``<config dir>/logs/slave.log``
|
||||
so tablet/Pi problems can be diagnosed after the fact.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
_configured = False
|
||||
_FMT = logging.Formatter(
|
||||
"%(asctime)s | %(levelname)-7s | %(name)s - %(message)s", datefmt="%H:%M:%S",
|
||||
)
|
||||
|
||||
|
||||
def _configure_once() -> None:
|
||||
global _configured
|
||||
if _configured:
|
||||
return
|
||||
root = logging.getLogger("javis_slave")
|
||||
root.setLevel(logging.INFO)
|
||||
root.propagate = False
|
||||
|
||||
handler = logging.StreamHandler(sys.stderr)
|
||||
handler.setFormatter(_FMT)
|
||||
root.addHandler(handler)
|
||||
|
||||
try:
|
||||
from .config import config_dir
|
||||
log_dir = config_dir() / "logs"
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
fh = RotatingFileHandler(log_dir / "slave.log", maxBytes=2_000_000,
|
||||
backupCount=3, encoding="utf-8")
|
||||
fh.setFormatter(logging.Formatter(
|
||||
"%(asctime)s | %(levelname)-7s | %(name)s - %(message)s"))
|
||||
root.addHandler(fh)
|
||||
except Exception as exc: # noqa: BLE001 (read-only FS etc. — stderr still works)
|
||||
root.warning(f"file logging disabled: {exc}")
|
||||
_configured = True
|
||||
|
||||
|
||||
def get_logger(name: str) -> logging.Logger:
|
||||
_configure_once()
|
||||
return logging.getLogger(f"javis_slave.{name}")
|
||||
Reference in new issue
Block a user