如何配置Python3日志以使用通配符过滤所有内容?cherrypy.access为每个客户端连接使用随机值或线程id,如“cherrypy.access.173118160”。下面是我一直想弄清楚如何过滤“loggers”中的“cherrypy.access.*”,有人知道怎么做吗
import os
import logging
import logging.config
def getLogger(name):
if loggers.get(name):
return loggers.get(name)
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)-11.11s] [%(name)s] [%(threadName)-12.12s] [%(funcName)s:%(lineno)d] %(message)s'
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard',
'stream': 'ext://sys.stdout'
},
'rotateBytesFile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'standard',
'filename': '%s/%s' % (os.getcwd(), '/logs/example.log'),
'maxBytes': 10485760,
'backupCount': 10
}
},
'loggers': {
'': {
'level': 'DEBUG',
'handlers': ['console', 'rotateBytesFile'],
'propagate': False
},
'cherrypy.access': {
'level': 'WARNING',
'handlers': ['console', 'rotateBytesFile'],
'propagate': False
},
}
})
return logging.getLogger(name)
目前没有回答
相关问题 更多 >
编程相关推荐