fix: simplify further
CI / lint (push) Skipped
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / lint (pull_request) Failing after 22s
CI / test (3.11) (pull_request) Skipped
CI / test (3.12) (pull_request) Skipped
CI / test (3.13) (pull_request) Skipped

This commit is contained in:
2026-08-14 15:50:37 +02:00
parent be5e971ff4
commit d74e6bb538
2 changed files with 31 additions and 63 deletions
+31 -31
View File
@@ -1,9 +1,6 @@
import logging
import logging.config
import os
from pathlib import Path
import yaml
class IgnoreSuccessfulStatusAccessFilter(logging.Filter):
@@ -69,43 +66,46 @@ def get_uvicorn_logging_config() -> dict:
}
def get_log_config() -> dict:
config_path = Path(__file__).parent / "logging.yaml"
if not config_path.exists():
raise FileNotFoundError(f"Logging config not found: {config_path}")
with open(config_path, "r") as f:
return yaml.safe_load(f.read())
AARE_LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {"format": "%(asctime)s - %(levelname)s - %(message)s"},
"journal": {"format": "%(message)s"},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "simple",
"level": "DEBUG",
"stream": " ext://sys.stdout",
},
"journal": {
"class": "systemd.journal.JournalHandler",
"formatter": "journal",
"level": "DEBUG",
},
},
"loggers": {
"aareDAQ": {"level": "DEBUG"},
"aareGUI": {"level": "DEBUG"},
"redis_lock": {"level": "WARNING"},
"urllib3": {"level": "WARNING"},
"matplotlib": {"level": "WARNING"},
},
"root": {"level": "WARNING", "handlers": ["console"]},
}
_SETUP_DONE: bool = False
def setup_logger(name: str, base_dir: str = "~/tmp/mxlogs/"):
def setup_logger(name: str):
global _SETUP_DONE
if _SETUP_DONE:
return logging.getLogger(name)
config = get_log_config()
# Force base directory to be under the user's home dir
effective_base = base_dir + name
effective_base = os.path.abspath(os.path.expanduser(os.path.expandvars(effective_base)))
# Ensure directories for file handlers exist
handlers = config.get("handlers", {})
for h in handlers.values():
filename = h.get("filename")
if not filename:
continue
abs_filename = os.path.join(effective_base, os.path.basename(filename))
h["filename"] = abs_filename
log_dir = os.path.dirname(abs_filename)
if log_dir and not os.path.exists(log_dir):
os.makedirs(log_dir, exist_ok=True)
logging.config.dictConfig(config)
logging.config.dictConfig(AARE_LOG_CONFIG)
_SETUP_DONE = True
return logging.getLogger(name)
-32
View File
@@ -1,32 +0,0 @@
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(levelname)s - %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: simple
level: DEBUG
stream: ext://sys.stdout
journal:
class: systemd.journal.JournaldLogHandler
level: DEBUG
loggers:
aaredaq:
level: DEBUG
aaregui:
level: DEBUG
redis_lock:
level: WARNING
urllib3:
level: WARNING
matplotlib:
level: WARNING
root:
level: WARNING
handlers: [console, journal]