I cannot install a filter on a logging handler using dictConfig()
syntax. LoggingErrorFilter.filter()
is simply ignored, nothing happens.
I want to filter out error messages so that they do not appear twice in the log output. So I wrote LoggingErrorFilter
class and overrode filter()
.
My configuration:
class LoggingErrorFilter(logging.Filter):
def filter(self, record):
print 'filter!'
return record.levelno == logging.ERROR or record.levelno == logging.CRITICAL
config = {
'version': 1,
'disable_existing_loggers' : False,
'formatters' : {
'standard' : {
'format' : '%(asctime)s %(levelname)s %(name)s::%(message)s',
},
},
'handlers' : {
'console': {
'class' : 'logging.StreamHandler',
'level' : level,
'formatter' : 'standard',
'stream' : 'ext://sys.stdout',
},
'errorconsole': {
'class' : 'logging.StreamHandler',
'level' : 'ERROR',
'formatter' : 'standard',
'stream' : 'ext://sys.stderr',
'filters' :['errorfilter',],
},
},
'filters': {
'errorfilter': {
'class' : 'LoggingErrorFilter',
}
},
'loggers' : {
'' : {
'handlers' : ['errorconsole','console',],
'level' : level,
'propagate' : True,
},
name : {
'handlers' : ['errorconsole','console',],
'level' : level,
'propagate' : False,
},
},
}
logging.config.dictConfig(config)
What am I doing wrong here? Why is my filter ignored?