Unify logging
Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
parent
709fb36701
commit
8b810c4000
1 changed files with 44 additions and 10 deletions
|
|
@ -6,16 +6,16 @@ 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.FORMATS = {
|
||||
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,
|
||||
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.FORMATS.get(record.levelno)
|
||||
log_fmt = self._color_mapping.get(record.levelno)
|
||||
formatter = logging.Formatter(log_fmt)
|
||||
return formatter.format(record)
|
||||
|
|
|
|||
Loading…
Reference in a new issue