Browse Source

update: pretty log output

dev
dnomd343 2 years ago
parent
commit
eeffb88294
  1. 8
      Utils/Logger.py
  2. 8
      log.py

8
Utils/Logger.py

@ -23,19 +23,21 @@ logLevel = { # log level
}[LogLevel.lower()] }[LogLevel.lower()]
dateFormat = '%Y-%m-%d %H:%M:%S' 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 # load fileHandler -> log file
fileHandler = logging.FileHandler(LogFile, encoding = 'utf-8') fileHandler = logging.FileHandler(LogFile, encoding = 'utf-8')
fileHandler.setFormatter(logging.Formatter( fileHandler.setFormatter(logging.Formatter(
logFormat, datefmt = dateFormat '[' + timeFormat + '] ' + logFormat,
datefmt = dateFormat
)) ))
fileHandler.setLevel(logging.DEBUG) # debug level for log file fileHandler.setLevel(logging.DEBUG) # debug level for log file
# load stdHandler -> stderr # load stdHandler -> stderr
stdHandler = colorlog.StreamHandler() stdHandler = colorlog.StreamHandler()
stdHandler.setFormatter(colorlog.ColoredFormatter( stdHandler.setFormatter(colorlog.ColoredFormatter(
'%(log_color)s' + logFormat, '%(light_black)s' + timeFormat + '%(log_color)s ' + logFormat,
datefmt = dateFormat, datefmt = dateFormat,
log_colors = logColor, log_colors = logColor,
stream = sys.stderr stream = sys.stderr

8
log.py

@ -1,10 +1,18 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Basis import Constant
Constant.LogLevel = 'DEBUG'
from Utils.Logger import logger from Utils.Logger import logger
import requests
logger.debug('debug') logger.debug('debug')
logger.info('info') logger.info('info')
logger.warning('warning') logger.warning('warning')
logger.error('error') logger.error('error')
logger.critical('critical') logger.critical('critical')
requests.get('https://baidu.com')

Loading…
Cancel
Save