add rich logger

This commit is contained in:
grillazz 2021-09-01 09:49:38 +02:00
parent 72ef1bebb9
commit 71588752e1

17
the_app/utils.py Normal file
View File

@ -0,0 +1,17 @@
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")
@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