diff src/core/log_config.py @ 1942:7f053e1f0b67

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.
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:35:17 +0200
parents befdcfc55569
children 0931b5a6213c
line wrap: on
line diff
--- a/src/core/log_config.py	Mon Apr 18 18:33:59 2016 +0200
+++ b/src/core/log_config.py	Mon Apr 18 18:35:17 2016 +0200
@@ -43,12 +43,13 @@
 
 class ConfigureBasic(log.ConfigureBase):
 
-    def configureColors(self, colors, force_colors):
+    def configureColors(self, colors, force_colors, levels_taints_dict):
+        super(ConfigureBasic, self).configureColors(colors, force_colors, levels_taints_dict)
         if colors:
             import sys
             if force_colors or sys.stdout.isatty(): # FIXME: isatty should be tested on each handler, not globaly
                 # we need colors
-                log.Logger.post_treat = lambda self, level, message: self.ansiColors(level, message)
+                log.Logger.post_treat = lambda logger, level, message: self.ansiColors(level, message)
         elif force_colors:
             raise ValueError("force_colors can't be used if colors is False")
 
@@ -210,7 +211,8 @@
         if C.LOG_OPT_OUTPUT_MEMORY in log.handlers:
             raise NotImplementedError("Memory observer is not implemented in Twisted backend")
 
-    def configureColors(self, colors, force_colors):
+    def configureColors(self, colors, force_colors, levels_taints_dict):
+        super(ConfigureTwisted, self).configureColors(colors, force_colors, levels_taints_dict)
         self.LOGGER_CLASS.colors = colors
         self.LOGGER_CLASS.force_colors = force_colors
         if force_colors and not colors:
@@ -235,12 +237,12 @@
 
 class ConfigureStandard(ConfigureBasic):
 
-    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):
         if fmt is None:
             fmt = C.LOG_OPT_FORMAT[1]
         if output is None:
             output = C.LOG_OPT_OUTPUT[1]
-        super(ConfigureStandard, self).__init__(level, fmt, output, logger, colors, force_colors, backend_data)
+        super(ConfigureStandard, self).__init__(level, fmt, output, logger, colors, levels_taints_dict, force_colors, backend_data)
 
     def preTreatment(self):
         """We use logging methods directly, instead of using Logger"""
@@ -295,7 +297,8 @@
     def configureLogger(self, logger):
         self.name_filter = log.FilterName(logger) if logger else None
 
-    def configureColors(self, colors, force_colors):
+    def configureColors(self, colors, force_colors, levels_taints_dict):
+        super(ConfigureStandard, self).configureColors(colors, force_colors, levels_taints_dict)
         self.formatterClass.with_colors = colors
         self.formatterClass.force_colors = force_colors
         if not colors and force_colors: