fix: simplify further
CI / lint (pull_request) Successful in 22s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.13) (pull_request) Successful in 55s
CI / test (3.12) (pull_request) Successful in 1m16s
CI / lint (push) Canceled after 12s
CI / test (3.11) (push) Canceled after 0s
CI / test (3.12) (push) Canceled after 0s
CI / test (3.13) (push) Canceled after 0s
Build and Publish / release (push) Successful in 11s

This commit was merged in pull request #18.
This commit is contained in:
2026-08-14 16:04:06 +02:00
parent be5e971ff4
commit 207612377d
2 changed files with 33 additions and 67 deletions
+33 -35
View File
@@ -1,9 +1,6 @@
import logging
import logging.config
import os
from pathlib import Path
import yaml
class IgnoreSuccessfulStatusAccessFilter(logging.Filter):
@@ -69,44 +66,45 @@ 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"}},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "simple",
"level": "DEBUG",
"stream": " ext://sys.stdout",
}
},
"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
_setup_done: bool = False
_additional_loggers_setup: set[str] = set()
def setup_logger(name: str, base_dir: str = "~/tmp/mxlogs/"):
global _SETUP_DONE
if _SETUP_DONE:
return logging.getLogger(name)
def setup_logger(name: str):
logger = logging.getLogger(name)
if name not in _additional_loggers_setup:
_additional_loggers_setup.add(name)
logger.setLevel(logging.DEBUG)
config = get_log_config()
global _setup_done
if _setup_done:
return logger
# 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)
_SETUP_DONE = True
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]