From bfafd890d0b25b6b742442067766926952d6fb35 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 9 Jun 2024 06:42:28 -0700 Subject: [PATCH] tweak logging --- domain/Logger.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/domain/Logger.py b/domain/Logger.py index 494c17b..733d162 100644 --- a/domain/Logger.py +++ b/domain/Logger.py @@ -4,9 +4,10 @@ from logging.handlers import SysLogHandler import sys + class Logger: - def __init__(self, name: str, debug: bool=False): + def __init__(self, name: str, debug: bool = False): self.__name = name @@ -19,8 +20,14 @@ class Logger: self.__logger.setLevel(level) - formatter = logging.Formatter('[%(name)s][%(levelname)s] %(message)s') - formatter_full = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s') + formatter = logging.Formatter( + fmt="[{name}][{levelname:<7}] {message}", + style='{' + ) + formatter_full = logging.Formatter( + fmt="[{asctime}][{name}][{levelname:<7}] {message}", + style='{' + ) # Console output / stream handler (STDOUT) handler = logging.StreamHandler( @@ -48,17 +55,22 @@ class Logger: self.__logger.addHandler(handler) # This is annoying inside cron - # self.debug("Test debug log") - # self.info("Test info log") - # self.warn("Test warn log") - # self.error("Test error log") - + self.debug("Test debug log") + self.info("Test info log") + self.warn("Test warn log") + self.error("Test error log") def debug(self, s): self.__logger.debug(s) + def info(self, s): self.__logger.info(s) + def warn(self, s): - self.__logger.warn(s) + self.__logger.warning(s) + + def warning(self, s): + self.__logger.warning(s) + def error(self, s): self.__logger.error(s)