forked from Hay1tsme/artemis
Centralized logging
Allows us to extend the logging infrastructure, e.g. by adding Loki/Discord webhooks to the mix.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user