core (logs): taints:
log taints can be specified using log_levels_taints_dict in sat.conf, where key is a level name, and value is a list of color or code names. For instance, the following conf would taint INFO level in bold/green and DEBUG in default color:
log_levels_taints_dict = {"debug": [], "info": ["green", "bold"]}
Unknown names are copied as raw strings.
This commit is contained in:
parent
864520086a
commit
1e05785e83
1 changed files with 56 additions and 37 deletions
|
|
@ -159,7 +159,7 @@ class ConfigureBase(object):
|
|||
LOGGER_CLASS = Logger
|
||||
_color_location = False # True if color location is specified in fmt (with COLOR_START)
|
||||
|
||||
def __init__(self, level=None, fmt=None, output=None, logger=None, colors=False, force_colors=False, backend_data=None):
|
||||
def __init__(self, level=None, fmt=None, output=None, logger=None, colors=False, levels_taints_dict=None, force_colors=False, backend_data=None):
|
||||
"""Configure a backend
|
||||
|
||||
@param level: one of C.LOG_LEVELS
|
||||
|
|
@ -178,7 +178,7 @@ class ConfigureBase(object):
|
|||
self.configureFormat(fmt)
|
||||
self.configureOutput(output)
|
||||
self.configureLogger(logger)
|
||||
self.configureColors(colors, force_colors)
|
||||
self.configureColors(colors, force_colors, levels_taints_dict)
|
||||
self.postTreatment()
|
||||
self.updateCurrentLogger()
|
||||
|
||||
|
|
@ -221,8 +221,29 @@ class ConfigureBase(object):
|
|||
if logger:
|
||||
Logger.filter_name = FilterName(logger)
|
||||
|
||||
def configureColors(self, colors, force_colors):
|
||||
pass
|
||||
def configureColors(self, colors, force_colors, levels_taints_dict):
|
||||
if colors:
|
||||
# if color are used, we need to handle levels_taints_dict
|
||||
for level in levels_taints_dict.keys():
|
||||
# we wants levels in uppercase to correspond to contstants
|
||||
levels_taints_dict[level.upper()] = levels_taints_dict[level]
|
||||
taints = self.__class__.taints = {}
|
||||
for level in C.LOG_LEVELS:
|
||||
# we want use values and use constant value as default
|
||||
taint_list = levels_taints_dict.get(level, C.LOG_OPT_TAINTS_DICT[1][level])
|
||||
ansi_list = []
|
||||
for elt in taint_list:
|
||||
elt = elt.upper()
|
||||
try:
|
||||
ansi = getattr(C, 'ANSI_FG_{}'.format(elt))
|
||||
except AttributeError:
|
||||
try:
|
||||
ansi = getattr(C, 'ANSI_{}'.format(elt))
|
||||
except AttributeError:
|
||||
# we use raw string if element is unknown
|
||||
ansi = elt
|
||||
ansi_list.append(ansi)
|
||||
taints[level] = ''.join(ansi_list)
|
||||
|
||||
def postTreatment(self):
|
||||
pass
|
||||
|
|
@ -289,29 +310,17 @@ class ConfigureBase(object):
|
|||
@param message: formatted message to log
|
||||
@return: message with ANSI escape codes for coloration
|
||||
"""
|
||||
if level == C.LOG_LVL_DEBUG:
|
||||
start = (C.ANSI_FG_CYAN,)
|
||||
elif level == C.LOG_LVL_INFO:
|
||||
start = ()
|
||||
elif level == C.LOG_LVL_WARNING:
|
||||
start = (C.ANSI_FG_YELLOW,)
|
||||
elif level == C.LOG_LVL_ERROR:
|
||||
start = (C.ANSI_FG_RED,
|
||||
C.ANSI_BLINK,
|
||||
r'/!\ ',
|
||||
C.ANSI_BLINK_OFF)
|
||||
elif level == C.LOG_LVL_CRITICAL:
|
||||
start = (C.ANSI_BOLD,
|
||||
C.ANSI_FG_RED,
|
||||
'Guru Meditation ',
|
||||
C.ANSI_NORMAL_WEIGHT)
|
||||
else:
|
||||
start = ()
|
||||
|
||||
try:
|
||||
start = cls.taints[level]
|
||||
except KeyError:
|
||||
start = ''
|
||||
|
||||
if cls._color_location:
|
||||
return message % {'color_start': ''.join(start),
|
||||
return message % {'color_start': start,
|
||||
'color_end': C.ANSI_RESET}
|
||||
else:
|
||||
return '%s%s%s' % (''.join(start), message, C.ANSI_RESET)
|
||||
return '%s%s%s' % (start, message, C.ANSI_RESET)
|
||||
|
||||
@staticmethod
|
||||
def getProfile():
|
||||
|
|
|
|||
Loading…
Reference in a new issue