1 logging.basicConfig(level=logging.DEBUG, 2 format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', 3 datefmt = '%a,%d %b %Y %H:%M:%S', 4 filename = 'test.log', 5 filemode = 'w') 6 logging.debug('debug message') 7 logging.info('info message') 8 logging.warning('warning message') 9 logging.error('error message') 10 logging.critical('crititcal message')
输出只有:
WARNING:root:warning message
ERROR:root:error message
CRITICAL:root:crititcal message
默认输出上面三个级别的
可以设置日志级别:
logging.basicConfig(level=logging.DEBUG,
format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt = '%a,%d %b %Y %H:%M:%S',
filename = 'test.log',
filemode = 'w')
filename 用指定的文件名创建,这样就会存储在指定的文件夹文件下