摘要
本文记录logging模块的使用方法
logging
日志级别
1 | CRITICAL = 50 #FATAL = CRITICAL |
默认级别为warning,默认打印到终端
1 | import logging |
为logging模块指定全局配置,针对所有logger有效,控制打印到文件中
1 | 可在logging.basicConfig()函数中通过具体参数来更改logging模块默认行为,可用参数有 |
1 | #======介绍 |
logging模块的Formatter,Handler,Logger,Filter对象
1 | #logger:产生日志的对象 |
1 | ''' |
Logger与Handler的级别
logger是第一级过滤,然后才能到handler,我们可以给logger和handler同时设置level,但是需要注意的是
1 | Logger is also the first to filter the message based on a level — if you set the logger to INFO, and all handlers to DEBUG, you still won't receive DEBUG messages on handlers — they'll be rejected by the logger itself. If you set logger to DEBUG, but all handlers to INFO, you won't receive any DEBUG messages either — because while the logger says "ok, process this", the handlers reject it (DEBUG < INFO). |
Logger的继承(了解)
1 | import logging |
应用
logging配置文件
1 | """ |
使用
1 | """ |
关于如何拿到logger对象的详细解释
1 | 注意注意注意: |
另外一个django的配置,瞄一眼就可以,跟上面的一样
1 | #logging_config.py |
文件自动截断
1 | import logging |
other
1 | import logging |