Add WHIPPER_COLOR_LOG env var to color log output

Signed-off-by: Katharina Dröge <kate@commandmc.de>
This commit is contained in:
Katharina Dröge
2025-09-25 22:32:11 +02:00
parent bc8b96d956
commit f319fcda9d
2 changed files with 14 additions and 4 deletions

View File

@@ -14,8 +14,17 @@ except (DistributionNotFound, RequirementParseError):
level = logging.INFO
if 'WHIPPER_DEBUG' in os.environ:
level = os.environ['WHIPPER_DEBUG'].upper()
log_init_func = logging.basicConfig
if 'WHIPPER_COLOR_LOG' in os.environ:
import coloredlogs
def init_coloredlogs(**kwargs):
# coloredlogs comes with its own log format, we don't want to use that
coloredlogs.install(fmt=logging.BASIC_FORMAT, **kwargs)
log_init_func = init_coloredlogs
if 'WHIPPER_LOGFILE' in os.environ:
logging.basicConfig(filename=os.environ['WHIPPER_LOGFILE'],
filemode='w', level=level)
log_init_func(filename=os.environ['WHIPPER_LOGFILE'],
filemode='w', level=level)
else:
logging.basicConfig(stream=sys.stderr, level=level)
log_init_func(stream=sys.stderr, level=level)