我使用 python 2.7.5 我创建了一个包含记录器配置的文件:
[loggers]
keys=root,api
[logger_root]
handlers=screen,file
[logger_api]
handlers=fileapi
qualname=api
[formatters]
keys=simple,complex
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s
[handlers]
keys=file,screen,fileapi
[handler_screen]
class=StreamHandler
formatter=simple
level=NOTSET
args=(sys.stdout,)
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=NOTSET
args=('/var/log/FMV/fmv.log',)
[handler_fileapi]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=NOTSET
args=('/var/log/FMV/fmv_api.log',)
当我调用我的代码 logger.info 等时:
_api_logger = logging.getLogger("api")
_api_logger.info("/index was called")
_api_logger.debug("/index was called")
_api_logger.error("/index was called")
在我的日志文件(/var/log/FMV/fmv_api.log)中,我看到以下内容:
2013-06-12 01:17:55,599 - api - ERROR - api : 13 - /index was called
所以只有错误消息是记录到日志文件的。为什么它不将所有消息写入文件?