diff --git a/app/utils.py b/app/utils.py index ec35e63..0c94176 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,21 +1,18 @@ -import logging -from functools import lru_cache - -from rich.console import Console -from rich.logging import RichHandler - -console = Console(color_system="256", width=200, style="blue") +from threading import Lock -@lru_cache -def get_logger(module_name): - logger = logging.getLogger(module_name) - handler = RichHandler( - rich_tracebacks=True, console=console, tracebacks_show_locals=True - ) - handler.setFormatter( - logging.Formatter("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s") - ) - logger.addHandler(handler) - logger.setLevel(logging.DEBUG) - return logger +class SingletonMeta(type): + """ + This is a thread-safe implementation of Singleton. + """ + + _instances = {} + + _lock: Lock = Lock() + + def __call__(cls, *args, **kwargs): + with cls._lock: + if cls not in cls._instances: + instance = super().__call__(*args, **kwargs) + cls._instances[cls] = instance + return cls._instances[cls]