Logging module
logging module可以分成logger、handler、formatter等三大元件。Level | When it’s used |
---|---|
DEBUG | Detailed information, typically of interest only when diagnosing problems. |
INFO | Confirmation that things are working as expected. |
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. |
ERROR | Due to a more serious problem, the software has not been able to perform some function. |
CRITICAL | A serious error, indicating that the program itself may be unable to continue running. |
Level | Numeric value |
---|---|
CRITICAL | 50 |
ERROR | 40 |
WARNING | 30 |
INFO | 20 |
DEBUG | 10 |
NOTSET | 0 |
NOTEST < DEBUG < INFO < WARNING < ERROR < CRITICAL
如果把debug level設置為INFO,則<INFO的log將不會輸出,只有>= INFO的log才會輸出。
Logger.debug(msg [ ,*args [, **kwargs]])
记录DEBUG级别的日志信息。参数msg是信息的格式,args与kwargs分别是格式参数。
- import logging
- logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'), level = logging.DEBUG)
- log = logging.getLogger('root')
- log.debug('%s, %s, %s', *('error', 'debug', 'info'))
- log.debug('%(module)s, %(info)s', {'module': 'log', 'info': 'error'})
Logger.info(msg[ , *args[ , **kwargs] ] )
Logger.warnning(msg[ , *args[ , **kwargs] ] )
Logger.error(msg[ , *args[ , **kwargs] ] )
Logger.critical(msg[ , *args[ , **kwargs] ] )
记录相应级别的日志信息。参数的含义与Logger.debug一样。
logger.conf
qualname
he qualname entry is the hierarchical channel name of the logger, that is to say the name used by the application to get the logger.Reference:
1. python logging module 入門, http://blog.csdn.net/jgood/article/details/4340740
2. http://www.icoding.co/2012/08/logging-html
沒有留言:
張貼留言