From 71588752e1bb085d0857f8fcdbfc8d1eb89e5ce8 Mon Sep 17 00:00:00 2001 From: grillazz Date: Wed, 1 Sep 2021 09:49:38 +0200 Subject: [PATCH] add rich logger --- the_app/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 the_app/utils.py diff --git a/the_app/utils.py b/the_app/utils.py new file mode 100644 index 0000000..d2f9f52 --- /dev/null +++ b/the_app/utils.py @@ -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