Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1941:befdcfc55569 | 1942:7f053e1f0b67 |
---|---|
41 self.twisted_log.msg(message.encode('utf-8', 'ignore'), sat_logged=True, level=level) | 41 self.twisted_log.msg(message.encode('utf-8', 'ignore'), sat_logged=True, level=level) |
42 | 42 |
43 | 43 |
44 class ConfigureBasic(log.ConfigureBase): | 44 class ConfigureBasic(log.ConfigureBase): |
45 | 45 |
46 def configureColors(self, colors, force_colors): | 46 def configureColors(self, colors, force_colors, levels_taints_dict): |
47 super(ConfigureBasic, self).configureColors(colors, force_colors, levels_taints_dict) | |
47 if colors: | 48 if colors: |
48 import sys | 49 import sys |
49 if force_colors or sys.stdout.isatty(): # FIXME: isatty should be tested on each handler, not globaly | 50 if force_colors or sys.stdout.isatty(): # FIXME: isatty should be tested on each handler, not globaly |
50 # we need colors | 51 # we need colors |
51 log.Logger.post_treat = lambda self, level, message: self.ansiColors(level, message) | 52 log.Logger.post_treat = lambda logger, level, message: self.ansiColors(level, message) |
52 elif force_colors: | 53 elif force_colors: |
53 raise ValueError("force_colors can't be used if colors is False") | 54 raise ValueError("force_colors can't be used if colors is False") |
54 | 55 |
55 @staticmethod | 56 @staticmethod |
56 def getProfile(): | 57 def getProfile(): |
208 addObserver(self.twisted_log.FileLogObserver(log_file).emit) | 209 addObserver(self.twisted_log.FileLogObserver(log_file).emit) |
209 | 210 |
210 if C.LOG_OPT_OUTPUT_MEMORY in log.handlers: | 211 if C.LOG_OPT_OUTPUT_MEMORY in log.handlers: |
211 raise NotImplementedError("Memory observer is not implemented in Twisted backend") | 212 raise NotImplementedError("Memory observer is not implemented in Twisted backend") |
212 | 213 |
213 def configureColors(self, colors, force_colors): | 214 def configureColors(self, colors, force_colors, levels_taints_dict): |
215 super(ConfigureTwisted, self).configureColors(colors, force_colors, levels_taints_dict) | |
214 self.LOGGER_CLASS.colors = colors | 216 self.LOGGER_CLASS.colors = colors |
215 self.LOGGER_CLASS.force_colors = force_colors | 217 self.LOGGER_CLASS.force_colors = force_colors |
216 if force_colors and not colors: | 218 if force_colors and not colors: |
217 raise ValueError('colors must be True if force_colors is True') | 219 raise ValueError('colors must be True if force_colors is True') |
218 | 220 |
233 self.log_publisher._originalAddObserver(twistedObserver) | 235 self.log_publisher._originalAddObserver(twistedObserver) |
234 | 236 |
235 | 237 |
236 class ConfigureStandard(ConfigureBasic): | 238 class ConfigureStandard(ConfigureBasic): |
237 | 239 |
238 def __init__(self, level=None, fmt=None, output=None, logger=None, colors=False, force_colors=False, backend_data=None): | 240 def __init__(self, level=None, fmt=None, output=None, logger=None, colors=False, levels_taints_dict=None, force_colors=False, backend_data=None): |
239 if fmt is None: | 241 if fmt is None: |
240 fmt = C.LOG_OPT_FORMAT[1] | 242 fmt = C.LOG_OPT_FORMAT[1] |
241 if output is None: | 243 if output is None: |
242 output = C.LOG_OPT_OUTPUT[1] | 244 output = C.LOG_OPT_OUTPUT[1] |
243 super(ConfigureStandard, self).__init__(level, fmt, output, logger, colors, force_colors, backend_data) | 245 super(ConfigureStandard, self).__init__(level, fmt, output, logger, colors, levels_taints_dict, force_colors, backend_data) |
244 | 246 |
245 def preTreatment(self): | 247 def preTreatment(self): |
246 """We use logging methods directly, instead of using Logger""" | 248 """We use logging methods directly, instead of using Logger""" |
247 import logging | 249 import logging |
248 log.getLogger = logging.getLogger | 250 log.getLogger = logging.getLogger |
293 self.manageOutputs(output) | 295 self.manageOutputs(output) |
294 | 296 |
295 def configureLogger(self, logger): | 297 def configureLogger(self, logger): |
296 self.name_filter = log.FilterName(logger) if logger else None | 298 self.name_filter = log.FilterName(logger) if logger else None |
297 | 299 |
298 def configureColors(self, colors, force_colors): | 300 def configureColors(self, colors, force_colors, levels_taints_dict): |
301 super(ConfigureStandard, self).configureColors(colors, force_colors, levels_taints_dict) | |
299 self.formatterClass.with_colors = colors | 302 self.formatterClass.with_colors = colors |
300 self.formatterClass.force_colors = force_colors | 303 self.formatterClass.force_colors = force_colors |
301 if not colors and force_colors: | 304 if not colors and force_colors: |
302 raise ValueError("force_colors can't be used if colors is False") | 305 raise ValueError("force_colors can't be used if colors is False") |
303 | 306 |