From 206b8ebf458f10c9f77dea0aa905b47394e1ad34 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Mar 2023 23:06:46 -0500 Subject: [PATCH] [+] Initialize rich logger --- tngame/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tngame/utils.py diff --git a/tngame/utils.py b/tngame/utils.py new file mode 100644 index 0000000..9ac4f0e --- /dev/null +++ b/tngame/utils.py @@ -0,0 +1,23 @@ +import logging + + +def setup_logger(debug: bool): + # Try to use rich for pretty printing + try: + from rich.logging import RichHandler + handler = RichHandler(rich_tracebacks=True) + + from rich.traceback import install + install(show_locals=True) + except ImportError: + handler = logging.StreamHandler() + + # Initialize debug logger + logging.basicConfig( + level="NOTSET" if debug else "INFO", + format="%(message)s", + datefmt="[%X]", + handlers=[handler] + ) + + return logging.getLogger("a2")