logging模块
什么时候使用logging
Task you want to perform
The best tool for the task
Display console output for ordinary usage of a command line script or program
print()
Report events that occur during normal operation of a program (e.g. for status monitoring or fault investigation)
logging.info()
(or logging.debug()
for very detailed output for diagnostic purposes)
Issue a warning regarding a particular runtime event
Report an error regarding a particular runtime event
Raise an exception
Report suppression of an error without raising an exception (e.g. error handler in a long-running server process)
级别
Level
When it’s used
Numeric value
DEBUG
Detailed information, typically of interest only when diagnosing problems.
10
INFO
Confirmation that things are working as expected.
20
WARNING
An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
30
ERROR
Due to a more serious problem, the software has not been able to perform some function.
40
CRITICAL
A serious error, indicating that the program itself may be unable to continue running.
50
NOTSET
0
基本用法
代码
输出
注意
DEBUG
和INFO
级别日志没有在控制台显示, 是因为默认级别是WARNING
保存到文件
代码
输出
example.log
内的内容
最后更新于
这有帮助吗?