logging: Create a new level DEBUG_FILTERS

This is a cleaner approach that requires less configuration
in other applications.
This also easily allows us to have another color.

Many checks were made on being exactly at the DEBUG level, they were
fixed to also check on being below DEBUG (i.e. DEBUG_FILTERS).
This commit is contained in:
Laurent Bachelier 2014-10-07 17:07:48 +02:00
commit 7be9a6468b
12 changed files with 27 additions and 35 deletions

View file

@ -21,7 +21,7 @@ from __future__ import print_function
import sys
from collections import defaultdict
from logging import Filter, Formatter, getLogger as _getLogger
from logging import addLevelName, Formatter, getLogger as _getLogger
__all__ = ['getLogger', 'createColoredFormatter', 'settings']
@ -35,8 +35,12 @@ COLORS = {
'WARNING': COLOR_SEQ % "\033[1;33m",
'ERROR': COLOR_SEQ % "\033[1;31m",
'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"),
'DEBUG_FILTERS': COLOR_SEQ % "\033[0;35m",
}
DEBUG_FILTERS = 8
addLevelName(DEBUG_FILTERS, 'DEBUG_FILTERS')
# Global settings f logger.
settings = defaultdict(lambda: None)
@ -50,16 +54,6 @@ def getLogger(name, parent=None):
return logger
class DebugFilter(Filter):
"""
Allow a fine filtering of debug output
"""
def filter(self, record):
if record.name == "b2filters":
return False
return True
class ColoredFormatter(Formatter):
"""
Class written by airmind: