From eeffb882943a995ed5414a1bb8d919d55228b000 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Tue, 6 Sep 2022 19:36:07 +0800 Subject: [PATCH] update: pretty log output --- Utils/Logger.py | 8 +++++--- log.py | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Utils/Logger.py b/Utils/Logger.py index 6a4f93f..943a062 100644 --- a/Utils/Logger.py +++ b/Utils/Logger.py @@ -23,19 +23,21 @@ logLevel = { # log level }[LogLevel.lower()] dateFormat = '%Y-%m-%d %H:%M:%S' -logFormat = '[%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s (%(module)s.%(funcName)s)' +timeFormat = '%(asctime)s.%(msecs)03d' +logFormat = '[%(levelname)s] %(message)s (%(module)s.%(funcName)s:%(lineno)d)' # load fileHandler -> log file fileHandler = logging.FileHandler(LogFile, encoding = 'utf-8') fileHandler.setFormatter(logging.Formatter( - logFormat, datefmt = dateFormat + '[' + timeFormat + '] ' + logFormat, + datefmt = dateFormat )) fileHandler.setLevel(logging.DEBUG) # debug level for log file # load stdHandler -> stderr stdHandler = colorlog.StreamHandler() stdHandler.setFormatter(colorlog.ColoredFormatter( - '%(log_color)s' + logFormat, + '%(light_black)s' + timeFormat + '%(log_color)s ' + logFormat, datefmt = dateFormat, log_colors = logColor, stream = sys.stderr diff --git a/log.py b/log.py index 88ff870..c6a5722 100755 --- a/log.py +++ b/log.py @@ -1,10 +1,18 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from Basis import Constant + +Constant.LogLevel = 'DEBUG' + from Utils.Logger import logger +import requests + logger.debug('debug') logger.info('info') logger.warning('warning') logger.error('error') logger.critical('critical') + +requests.get('https://baidu.com')