Commit 638f1985 authored by Xavier Thompson's avatar Xavier Thompson

[fix] Fix logging filters for Python2

parent 35b7a793
......@@ -1284,16 +1284,23 @@ class Buildout(DictMixin):
root_logger = logging.getLogger()
self._logger = buildout_logger = logging.getLogger('zc.buildout')
# BBB Python2 (Python3 accepts lambdas as filters)
class Filter(object):
def __init__(self, callable):
self.callable = callable
def filter(self, record):
return self.callable(record)
# root-specific WARNING handler because setuptools>=65.6.0 logs to root
root_handler = logging.StreamHandler(sys.stdout)
root_handler.setLevel(logging.WARNING)
root_handler.addFilter(lambda record: record.name == 'root')
root_handler.addFilter(Filter(lambda record: record.name == 'root'))
root_handler.setFormatter(logging.Formatter(generic_log_format))
root_logger.addHandler(root_handler)
# generic handler for third-party logs
generic_handler = logging.StreamHandler(sys.stdout)
generic_handler.addFilter(lambda record: record.name != 'root')
generic_handler.addFilter(Filter(lambda record: record.name != 'root'))
generic_handler.setFormatter(logging.Formatter(generic_log_format))
root_logger.addHandler(generic_handler)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment