Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
A, Formatter
format |
description |
%(levelno)s |
Print log level values |
%(levelname)s |
Print the name of the log level |
%(pathname)s |
Print path of the currently executing program |
%(filename)s |
Print the name of the currently executing program |
%(funcName)s |
The current print log function |
%(lineno)d |
Print Log current line number |
%(asctime)s |
Print log time |
%(thread)d |
Print thread id |
%(threadName)s |
Print Thread name |
%(process)d |
Printing Process ID |
%(message)s |
Print log information |
Second, the reference code
#encoding='utf-8'
import logging
#打印debug以上的日志
# logging.basicConfig(level = logging.DEBUG)
#打印warning以上的日志
logging.basicConfig(level=logging.INFO,filename='run.log',
format='%(asctime)s %(filename)s[line:%(lineno)d]%(levelname)s%(message)s')
logging.debug('debug_打印debug日志')
logging.info('info_打印info日志')
logging.warning('warning_打印warning日志')
logging.error('error_打印error日志')
logging.critical('critical_打印critical日志')
Third, the problem is solved: Chinese garbled print the log, modify the logging code in the original default values
Fourth, the results