Move files
This commit is contained in:
parent
3cf28379e8
commit
00cc8225c5
159 changed files with 31 additions and 49 deletions
2
great_ai/utilities/logger/__init__.py
Normal file
2
great_ai/utilities/logger/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from .custom_formatter import CustomFormatter
|
||||
from .get_logger import get_logger
|
||||
6
great_ai/utilities/logger/colors.py
Normal file
6
great_ai/utilities/logger/colors.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
GREY = "\x1b[38;21m"
|
||||
BLUE = "\x1b[38;5;39m"
|
||||
YELLOW = "\x1b[38;5;226m"
|
||||
RED = "\x1b[38;5;196m"
|
||||
BOLD_RED = "\x1b[31;1m"
|
||||
RESET = "\x1b[0m"
|
||||
21
great_ai/utilities/logger/custom_formatter.py
Normal file
21
great_ai/utilities/logger/custom_formatter.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import logging
|
||||
|
||||
from .colors import BLUE, BOLD_RED, GREY, RED, RESET, YELLOW
|
||||
|
||||
|
||||
class CustomFormatter(logging.Formatter):
|
||||
def __init__(self, fmt: str):
|
||||
super().__init__()
|
||||
self._fmt = fmt
|
||||
self._color_mapping = {
|
||||
logging.DEBUG: GREY + self._fmt + RESET,
|
||||
logging.INFO: BLUE + self._fmt + RESET,
|
||||
logging.WARNING: YELLOW + self._fmt + RESET,
|
||||
logging.ERROR: RED + self._fmt + RESET,
|
||||
logging.CRITICAL: BOLD_RED + self._fmt + RESET,
|
||||
}
|
||||
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
log_fmt = self._color_mapping.get(record.levelno)
|
||||
formatter = logging.Formatter(log_fmt)
|
||||
return formatter.format(record)
|
||||
26
great_ai/utilities/logger/get_logger.py
Normal file
26
great_ai/utilities/logger/get_logger.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import logging
|
||||
from typing import Dict
|
||||
|
||||
from .custom_formatter import CustomFormatter
|
||||
|
||||
loggers: Dict[str, logging.Logger] = {}
|
||||
|
||||
|
||||
def get_logger(
|
||||
name: str, level: int = logging.INFO, disable_colors: bool = False
|
||||
) -> logging.Logger:
|
||||
if name not in loggers:
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(level)
|
||||
|
||||
fmt = "%(asctime)s | %(levelname)8s | %(message)s"
|
||||
|
||||
stdout_handler = logging.StreamHandler()
|
||||
stdout_handler.setLevel(level)
|
||||
if not disable_colors:
|
||||
stdout_handler.setFormatter(CustomFormatter(fmt))
|
||||
|
||||
logger.addHandler(stdout_handler)
|
||||
loggers[name] = logger
|
||||
|
||||
return loggers[name]
|
||||
Loading…
Add table
Add a link
Reference in a new issue