码迷,mamicode.com
首页 > 编程语言 > 详细

Python logging

时间:2017-04-12 01:42:59      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:this   set   err   level   conf   eve   log   win10   org   

拒绝print,使用 logging !

#https://docs.python.org/3.5/howto/logging.html?highlight=logging

#win10 + python 3.5.2

1. Logging to Console

import logging

#default level : WARNING  #30

#CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET

logging.debug(‘debug message‘)

logging.info(‘info message‘)

logging.warning(‘warning message‘)

 

>>> [log.CRITICAL ,log.ERROR, log.WARNING,log.INFO,log.DEBUG,log.NOTSET]
[50, 40, 30, 20, 10, 0]

>>> log.getLevelName(logger.getEffectiveLevel())
‘WARNING‘

 

2. Logging to a file

 

import logging
logging.basicConfig(filename=‘example.log‘,level=logging.DEBUG)
logging.debug(‘This message should go to the log file‘)
logging.info(‘So should this‘)
logging.warning(‘And this, too‘)

 

Python logging

标签:this   set   err   level   conf   eve   log   win10   org   

原文地址:http://www.cnblogs.com/squirrel2300/p/6697133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!