Reformat and remove stale debugging

This commit is contained in:
2026-02-16 19:50:17 +00:00
parent 658ab10647
commit f3ced1bfd8
10 changed files with 122 additions and 105 deletions

View File

@@ -1,9 +1,15 @@
# Other library imports
import logging
import os
log = logging.getLogger("util")
debug = True
debug = str(os.getenv("GIA_DEBUG_LOGS", "0")).strip().lower() in {
"1",
"true",
"yes",
"on",
}
# Color definitions
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
@@ -49,20 +55,26 @@ def get_logger(name):
color_formatter = ColoredFormatter(COLOR_FORMAT)
# formatter = logging.Formatter(
# Why is this so complicated?
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# ch.setFormatter(formatter)
ch.setFormatter(color_formatter)
# Define the logger on the base class
log = logging.getLogger(name)
log.setLevel(logging.INFO)
if debug:
log.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)
# Add the handler and stop it being silly and printing everything twice
log.addHandler(ch)
# Add exactly one stream handler per logger to avoid duplicate lines.
existing_handler = None
for handler in log.handlers:
if getattr(handler, "_gia_logger_handler", False):
existing_handler = handler
break
if existing_handler is None:
ch = logging.StreamHandler()
ch._gia_logger_handler = True
ch.setFormatter(color_formatter)
log.addHandler(ch)
existing_handler = ch
existing_handler.setLevel(logging.DEBUG if debug else logging.INFO)
log.propagate = False
return log