Mer*_*lin 8 python logging xdebug
如果在整个代码库中存在日志记录语句,如何设置记录器,以便在将代码部署到生产环境中时不必注释掉对记录器的每次调用?
这是我目前的代码:
import logging
logging.basicConfig(filename='./example.log', level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M')
logging.debug('debug failed')
logging.info('info failed')
logging.warning('A warning')
Run Code Online (Sandbox Code Playgroud)
日志记录有多个级别。根据日志记录级别的严重性,它将打印它。
Level Numeric value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
Run Code Online (Sandbox Code Playgroud)
根据日志记录级别,它将打印语句。
您在此处指定的级别是 level=logging.DEBUG。因此,除了未设置的日志级别之外的所有日志级别都应该打印出来。如果您只想打印关键级别,请更改 level=logging.CRITICAL
http://docs.python.org/release/2.5/lib/module-logging.html有更多信息