Grotti 3.5.0: Pagination, Logging, Deb-Paket, Makro-Doku, PLA-Match-Fix.
This commit is contained in:
1 parent
4ffe1dcfc6
commit
f1f79c2ce2
38 files changed
+1062
-75
No files matched your search
@@ -0,0 +1,52 @@
|
||||
"""Zentraler Logger für Dienst und journald (stdout)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
_CONFIGURED = False
|
||||
|
||||
LEVELS = {
|
||||
"critical": logging.CRITICAL,
|
||||
"error": logging.ERROR,
|
||||
"warning": logging.WARNING,
|
||||
"warn": logging.WARNING,
|
||||
"info": logging.INFO,
|
||||
"debug": logging.DEBUG,
|
||||
}
|
||||
|
||||
|
||||
def parse_level(value, default=logging.INFO):
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
text = str(value or "").strip().lower()
|
||||
return LEVELS.get(text, default)
|
||||
|
||||
|
||||
def setup(level="INFO"):
|
||||
"""Root-Logger einmalig auf stdout (systemd → journald)."""
|
||||
global _CONFIGURED
|
||||
resolved = parse_level(level)
|
||||
root = logging.getLogger()
|
||||
if _CONFIGURED:
|
||||
root.setLevel(resolved)
|
||||
return root
|
||||
root.handlers.clear()
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(
|
||||
logging.Formatter(
|
||||
"%(asctime)s %(levelname)s [%(name)s] %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
)
|
||||
root.addHandler(handler)
|
||||
root.setLevel(resolved)
|
||||
logging.getLogger("waitress").setLevel(logging.WARNING)
|
||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
_CONFIGURED = True
|
||||
return root
|
||||
|
||||
|
||||
def get(name="grotti"):
|
||||
return logging.getLogger(name)
|
||||
Reference in new issue
Block a user