33
在我正在写的python脚本中,我正在尝试使用日志记录模块来记录事件。我有以下代码来配置我的记录:Python日志记录不输出任何东西
ERROR_FORMAT = "%(levelname)s at %(asctime)s in %(funcName)s in %(filename) at line %(lineno)d: %(message)s"
DEBUG_FORMAT = "%(lineno)d in %(filename)s at %(asctime)s: %(message)s"
LOG_CONFIG = {'version':1,
'formatters':{'error':{'format':ERROR_FORMAT},
'debug':{'format':DEBUG_FORMAT}},
'handlers':{'console':{'class':'logging.StreamHandler',
'formatter':'debug',
'level':logging.DEBUG},
'file':{'class':'logging.FileHandler',
'filename':'/usr/local/logs/DatabaseUpdate.log',
'formatter':'error',
'level':logging.ERROR}},
'root':{'handlers':('console', 'file')}}
logging.config.dictConfig(LOG_CONFIG)
当我尝试运行logging.debug("Some string")
,我没有得到任何输出到控制台,即使this page in the docs说logging.debug
应该有根记录器输出的消息。为什么我的程序不输出任何内容,我该如何解决?
该文档说它的默认级别是NOTSET,它是0的级别,它应该输出所有内容...为什么不是这样? – Ben
@Ben它说的那个?我所能看到的只是“默认级别是WARNING,这意味着只有该级别及以上的事件才会被跟踪,除非日志包被配置为其他方式。” –
https://docs.python.org/3.6/library/logging.html#logging.Logger.setLevel – Ben