comparison src/core/log_config.py @ 1940:3fdacba9da68

core (logs): log color location can now be specified with %(color_start)s and %(color_end)s
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:33:59 +0200
parents 2daf7b4c6756
children befdcfc55569
comparison
equal deleted inserted replaced
1939:e68483c5a999 1940:3fdacba9da68
256 if level is None: 256 if level is None:
257 level = C.LOG_LVL_DEBUG 257 level = C.LOG_LVL_DEBUG
258 self.level = level 258 self.level = level
259 259
260 def configureFormat(self, fmt): 260 def configureFormat(self, fmt):
261 super(ConfigureStandard, self).configureFormat(fmt)
261 import logging 262 import logging
262 263
263 class SatFormatter(logging.Formatter): 264 class SatFormatter(logging.Formatter):
264 u"""Formatter which manage SàT specificities""" 265 u"""Formatter which manage SàT specificities"""
265 _format = fmt 266 _format = fmt
270 self.can_colors = can_colors 271 self.can_colors = can_colors
271 272
272 def format(self, record): 273 def format(self, record):
273 if self._with_profile: 274 if self._with_profile:
274 record.profile = ConfigureStandard.getProfile() 275 record.profile = ConfigureStandard.getProfile()
276 do_color = self.with_colors and (self.can_colors or self.force_colors)
277 if ConfigureStandard._color_location:
278 # we copy raw formatting strings for color_*
279 # as formatting is handled in ansiColors in this case
280 if do_color:
281 record.color_start = log.COLOR_START
282 record.color_end = log.COLOR_END
283 else:
284 record.color_start = record.color_end = ''
275 s = super(SatFormatter, self).format(record) 285 s = super(SatFormatter, self).format(record)
276 if self.with_colors and (self.can_colors or self.force_colors): 286 if do_color:
277 s = ConfigureStandard.ansiColors(record.levelname, s) 287 s = ConfigureStandard.ansiColors(record.levelname, s)
278 return s 288 return s
279 289
280 self.formatterClass = SatFormatter 290 self.formatterClass = SatFormatter
281 291