Skip to content

Commit 39620fb

Browse files
committed
Add Log Colouring
1 parent 0202fe6 commit 39620fb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

cppython/builder.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""Defines the data and routines for building a CPPython project type"""
22

33
import logging
4+
import os
45
from importlib.metadata import entry_points
56
from inspect import getmodule
67
from logging import Logger
78
from typing import Any, cast
89

10+
from rich.console import Console
11+
from rich.logging import RichHandler
12+
913
from cppython.core.plugin_schema.generator import Generator
1014
from cppython.core.plugin_schema.provider import Provider
1115
from cppython.core.plugin_schema.scm import SCM, SupportedSCMFeatures
@@ -471,8 +475,28 @@ def __init__(self, project_configuration: ProjectConfiguration, logger: Logger)
471475
self._project_configuration = project_configuration
472476
self._logger = logger
473477

474-
# Add default output stream
475-
self._logger.addHandler(logging.StreamHandler())
478+
# Informal standard to check for color
479+
force_color = os.getenv('FORCE_COLOR', '1') != '0'
480+
481+
console = Console(
482+
force_terminal=force_color,
483+
color_system='auto',
484+
width=120,
485+
legacy_windows=False,
486+
no_color=False,
487+
)
488+
489+
rich_handler = RichHandler(
490+
console=console,
491+
rich_tracebacks=True,
492+
show_time=False,
493+
show_path=False,
494+
markup=True,
495+
show_level=False,
496+
enable_link_path=False,
497+
)
498+
499+
self._logger.addHandler(rich_handler)
476500
self._logger.setLevel(Builder.levels[project_configuration.verbosity])
477501

478502
self._logger.info('Logging setup complete')

0 commit comments

Comments
 (0)