首页 > 代码库 > Python logging
Python logging
拒绝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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。