Centralized logging

Allows us to extend the logging infrastructure, e.g. by adding Loki/Discord webhooks to the mix.
This commit is contained in:
2024-04-20 12:11:37 +00:00
parent 36ab38b1ee
commit 994fa0d41e
136 changed files with 340 additions and 847 deletions

View File

@ -2,7 +2,8 @@ from typing import Any, Callable
from functools import wraps
import hashlib
import pickle
import logging
import core.logger
from core.config import CoreConfig
cfg: CoreConfig = None # type: ignore
@ -39,11 +40,11 @@ def cached(lifetime: int = 10, extra_key: Any = None) -> Callable:
try:
result = memcache.get(cache_key)
except pylibmc.Error as e:
logging.getLogger("database").error(f"Memcache failed: {e}")
core.logger.create_logger("Database").error(f"Memcache failed: {e}")
result = None
if result is not None:
logging.getLogger("database").debug(f"Cache hit: {result}")
core.logger.create_logger("Database").debug(f"Cache hit: {result}")
return result
# Generate output
@ -51,7 +52,7 @@ def cached(lifetime: int = 10, extra_key: Any = None) -> Callable:
# Cache output if allowed
if lifetime is not None and result is not None:
logging.getLogger("database").debug(f"Setting cache: {result}")
core.logger.create_logger("Database").debug(f"Setting cache: {result}")
memcache.set(cache_key, result, lifetime)
return result