2013年5月15日 星期三

Python: logging module


Logging module

logging module可以分成logger、handler、formatter等三大元件。

LevelWhen it’s used
DEBUGDetailed information, typically of interest only when diagnosing problems.
INFOConfirmation that things are working as expected.
WARNINGAn 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.
ERRORDue to a more serious problem, the software has not been able to perform some function.
CRITICALA serious error, indicating that the program itself may be unable to continue running.


LevelNumeric value
CRITICAL50
ERROR40
WARNING30
INFO20
DEBUG10
NOTSET0

NOTEST < DEBUG < INFO < WARNING < ERROR < CRITICAL

如果把debug level設置為INFO,則<INFO的log將不會輸出,只有>= INFO的log才會輸出。


Logger.debug(msg [ ,*args [, **kwargs]])

  记录DEBUG级别的日志信息。参数msg是信息的格式,args与kwargs分别是格式参数。
[python] view plaincopy
  1. import logging  
  2. logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'), level = logging.DEBUG)  
  3. log = logging.getLogger('root')  
  4. log.debug('%s, %s, %s', *('error''debug''info'))  
  5. 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

沒有留言:

張貼留言