From b748a217a019aed65297b57464b6893ef0a7399d Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Thu, 9 Mar 2023 02:42:03 -0500 Subject: [PATCH] [+] Logging utils --- hypy_utils/logging_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 hypy_utils/logging_utils.py diff --git a/hypy_utils/logging_utils.py b/hypy_utils/logging_utils.py new file mode 100644 index 0000000..3b663b7 --- /dev/null +++ b/hypy_utils/logging_utils.py @@ -0,0 +1,24 @@ +import logging +import os + + +def setup_logger(debug: bool = os.environ.get("DEBUG", False)): + # 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")