I have a log.ini like this:
[handler_info]
class=StreamHandler
level=INFO
formatter=fmt
filter=infofilter
args=(sys.stdout,)
[handler_error]
class=StreamHandler
level=ERROR
filter=errorfilter
formatter=fmt
args=(sys.stdout,)
[filter_infofilter]
class=util.testfm.InfoFilter
[filter_errorfilter]
class=util.testfm.ErrorFilter
But it dosen't work. And I don't want to dynamic add filter for the handler like handler.addFilter(logging.Filter('foo'))
My filter like this:
class InfoFilter(logging.Filter):
def filter(self, rec):
return rec.levelno <= logging.INFO
class ErrorFilter(logging.Filter):
def filter(self, rec):
return rec.levelno > logging.INFO
What I want to achieve? I want to use one logger and two different handler to write different level log into different files.
I aslo find " If you need to have instances of Filter in your logging configuration, you will need to use dictConfig() " in https://docs.python.org/2/library/logging.config.html.
Seem like I can only do something like:
class InfoHandler(StreamHandler):
def __init__(self, *args, **kwargs):
StreamHandler.__init__(self, *args, **kwargs)
self.addFilter(InfoFilter())
class ErrorHandler(StreamHandler):
def __init__(self, *args, **kwargs):
StreamHandler.__init__(self, *args, **kwargs)
self.addFilter(ErrorFilter())
add make ini like :
[handler_error]
class=misc.testfm.ErrorHandler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With