diff --git a/data/Pedt/debug.py b/data/Pedt/debug.py new file mode 100755 index 0000000..8740d03 --- /dev/null +++ b/data/Pedt/debug.py @@ -0,0 +1,54 @@ +import logging +import os + +class Debug: + _logger = None + DEBUG_LOG=True + @classmethod + def setup_logger(cls, log_file,level=logging.INFO,console=False): + if cls._logger is not None: + return + + os.makedirs(os.path.dirname(log_file), exist_ok=True) + cls._logger = logging.getLogger('Pedt') + cls._logger.setLevel(level) + + file_handler = logging.FileHandler(log_file) + file_handler.setLevel(level) + formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') + file_handler.setFormatter(formatter) + cls._logger.addHandler(file_handler) + + if console: + console_handler = logging.StreamHandler() + console_handler.setLevel(level) + console_handler.setFormatter(formatter) + cls._logger.addHandler(console_handler) + + @classmethod + def debug(cls, *args): + if cls.DEBUG_LOG: + # stack = inspect.stack() + # frame = stack[1].frame + # function_name = frame.f_code.co_name + # line = frame.f_lineno + message = ' '.join(map(str, args)) + cls._logger.debug(message) + + @classmethod + def info(cls, *args): + if cls.DEBUG_LOG: + message = ' '.join(map(str, args)) + cls._logger.info(message) + + @classmethod + def warn(cls, *args): + if cls.DEBUG_LOG: + message = ' '.join(map(str, args)) + cls._logger.warn(message) + + @classmethod + def error(cls, *args): + if cls.DEBUG_LOG: + message = ' '.join(map(str, args)) + cls._logger.error(message)