其他分享
首页 > 其他分享> > 必备logging初始配置

必备logging初始配置

作者:互联网

import logging
import sys

logger = logging.getLogger()
logger.setLevel(logging.INFO)
rf_handler = logging.StreamHandler(sys.stderr)
rf_handler.setLevel(logging.DEBUG)
rf_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s %(message)s"))

f_handler = logging.FileHandler('log_path\\logs.log')
f_handler.setLevel(logging.INFO)
f_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s - %(filename)s[:%(lineno)d]"))

logger.addHandler(rf_handler)
logger.addHandler(f_handler)

logger.debug('debug messages')
logger.info('info messages')
logger.warning('warning messages')
logger.error('error messages')
logger.critical('critical messages')

标签:logging,必备,messages,rf,handler,logger,setLevel,初始
来源: https://blog.csdn.net/M_Power2/article/details/120991041