|
@@ -5,21 +5,7 @@ import time
|
|
|
|
|
|
|
|
from typing import Callable, ClassVar, Final
|
|
from typing import Callable, ClassVar, Final
|
|
|
|
|
|
|
|
-GREY: Final[str] = "\x1b[38;20m"
|
|
|
|
|
-YELLOW: Final[str] = "\x1b[33;20m"
|
|
|
|
|
-BLUE: Final[str] = "\x1b[34;20m"
|
|
|
|
|
-CYAN: Final[str] = "\x1b[36;20m"
|
|
|
|
|
-RED: Final[str] = "\x1b[31;20m"
|
|
|
|
|
-
|
|
|
|
|
-BOLD_RED: Final[str] = "\x1b[31;1m"
|
|
|
|
|
-BOLD_PURPLE: Final[str] = "\x1b[35;1m"
|
|
|
|
|
-
|
|
|
|
|
-RESET: Final[str] = "\x1b[0m"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def colored(code: str | None, fmt: str) -> str:
|
|
|
|
|
- """Apply a given color code"""
|
|
|
|
|
- return f"{code}{fmt}{RESET}" if code else fmt
|
|
|
|
|
|
|
+from colored import Fore, Style
|
|
|
|
|
|
|
|
|
|
|
|
|
class CIFormatter(logging.Formatter):
|
|
class CIFormatter(logging.Formatter):
|
|
@@ -30,11 +16,10 @@ class CIFormatter(logging.Formatter):
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
DEFAULT_COLOR_CODES: Final[ClassVar[dict[int, str]]] = {
|
|
DEFAULT_COLOR_CODES: Final[ClassVar[dict[int, str]]] = {
|
|
|
- logging.DEBUG: BOLD_PURPLE,
|
|
|
|
|
- logging.INFO: GREY,
|
|
|
|
|
- logging.WARNING: YELLOW,
|
|
|
|
|
- logging.ERROR: RED,
|
|
|
|
|
- logging.CRITICAL: BOLD_RED,
|
|
|
|
|
|
|
+ logging.DEBUG: Fore.deep_pink_4a + Style.BOLD,
|
|
|
|
|
+ logging.WARNING: Fore.yellow,
|
|
|
|
|
+ logging.ERROR: Fore.red,
|
|
|
|
|
+ logging.CRITICAL: Fore.red + Style.BOLD,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
converter: Callable[[float | None], time.struct_time] = time.gmtime
|
|
converter: Callable[[float | None], time.struct_time] = time.gmtime
|
|
@@ -57,7 +42,7 @@ class CIFormatter(logging.Formatter):
|
|
|
|
|
|
|
|
def _dispatch(self, level: int) -> logging.Formatter:
|
|
def _dispatch(self, level: int) -> logging.Formatter:
|
|
|
fmt = logging.Formatter(
|
|
fmt = logging.Formatter(
|
|
|
- fmt=colored(self._color_codes.get(level), self._format),
|
|
|
|
|
|
|
+ fmt=self._color_codes.get(level, "") + self._format + Style.reset,
|
|
|
datefmt=self.datefmt,
|
|
datefmt=self.datefmt,
|
|
|
)
|
|
)
|
|
|
fmt.converter = self.converter
|
|
fmt.converter = self.converter
|