一, logging 基本 https://www.cnblogs.com/huaizhi/p/11245246.html
import logging
logging.basicConfig() --- 默认项
- logging.debug('This is a debug message')
- logging.info('This is an info message')
- logging.warning('This is a warning message')
- logging.error('This is an error message')
- logging.critical('This is a critical message')
=========== 默认配置项, 只会打印 warning 级别以及以上级别
- WARNING:root:This is a warning message
- ERROR:root:This is an error message
- CRITICAL:root:This is a critical message
添加参数后:
- import logging
- logging.basicConfig(filename='log.text', filemode='w', format="%(asctime)s %(name)s %(levelname)s:%(message)s",
datefmt='%d-%M-%Y %H:%M:%S', level=logging.INFO) -- 指定了文件后, 就不会再控制台打印, 会直接存到指定文件中
- logging.debug('This is a debug message')
- logging.info('This is an info message')
- logging.warning('This is a warning message')
- logging.error('This is an error message')
- logging.critical('This is a critical message')
- try:
- print(5 / 0)
- except Exception as e:
logging.exception('occurred') -- 可以打印出具体的问题.
1. 实现一个 py 文件一个日志, 且日志大于 5M 自动覆盖 https://www.cnblogs.com/yfacesclub/p/9001073.html
2.
来源: http://www.bubuko.com/infodetail-3343994.html