实际上,
Tupteq的答案通常是不正确的。以下脚本:
import loggingimport logging.configimport sysclass MyFilter(logging.Filter): def __init__(self, param=None): self.param = param def filter(self, record): if self.param is None: allow = True else: allow = self.param not in record.msg if allow: record.msg = 'changed: ' + record.msg return allowLOGGING = { 'version': 1, 'filters': { 'myfilter': { '()': MyFilter, 'param': 'noshow', } }, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'filters': ['myfilter'] } }, 'root': { 'level': 'DEBUG', 'handlers': ['console'] },}if __name__ == '__main__': print(sys.version) logging.config.dictConfig(LOGGING) logging.debug('hello') logging.debug('hello - noshow')
运行时,将产生以下输出:
$ python filtcfg.py 2.7.5+ (default, Sep 19 2013, 13:48:49) [GCC 4.8.1]changed: hello
这表明您 可以 使用 来 配置过滤器
dictConfig()。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)