Enhance logging and error handling in collection access methods and WSGI configuration

This commit is contained in:
Ross
2026-04-13 13:44:25 +01:00
parent 463a741185
commit 90c8f0b60d
4 changed files with 38 additions and 8 deletions
+11 -2
View File
@@ -22,9 +22,18 @@ try:
# ensure directory exists
log_dir = Path("/var/log/rad")
log_dir.mkdir(parents=True, exist_ok=True)
# Determine stdout level: allow overriding with LOGURU_STDOUT_LEVEL env var,
# otherwise expose DEBUG when DEBUG env var is truthy, fall back to INFO.
raw_debug = os.environ.get("DEBUG", "0")
env_level = os.environ.get("LOGURU_STDOUT_LEVEL")
if env_level:
stdout_level = env_level
else:
stdout_level = "DEBUG" if raw_debug.lower() in ("1", "true", "yes") else "INFO"
# Add stdout sink (if not already added by other code)
logger.remove() # remove default handlers to avoid duplicate lines
logger.add(sys.stdout, level="INFO", enqueue=True, backtrace=False, diagnose=False)
logger.add(sys.stdout, level=stdout_level, enqueue=True, backtrace=False, diagnose=False)
# Add rotating file sink for persistence in container. Use JSON lines
# (serialize=True) to make logs easy to query in Loki/Grafana.
logger.add(
@@ -35,7 +44,7 @@ try:
enqueue=True,
serialize=True,
)
logger.debug("Loguru logging configured with stdout and file sinks")
logger.debug("Loguru logging configured with stdout and file sinks (stdout=%s)", stdout_level)
logging.root.setLevel(logging.DEBUG)
except Exception: