core (logs): log color location can now be specified with %(color_start)s and %(color_end)s

This commit is contained in:
Goffi 2016-04-18 18:33:59 +02:00
commit 304b1eb34b

View file

@ -258,6 +258,7 @@ class ConfigureStandard(ConfigureBasic):
self.level = level
def configureFormat(self, fmt):
super(ConfigureStandard, self).configureFormat(fmt)
import logging
class SatFormatter(logging.Formatter):
@ -272,8 +273,17 @@ class ConfigureStandard(ConfigureBasic):
def format(self, record):
if self._with_profile:
record.profile = ConfigureStandard.getProfile()
do_color = self.with_colors and (self.can_colors or self.force_colors)
if ConfigureStandard._color_location:
# we copy raw formatting strings for color_*
# as formatting is handled in ansiColors in this case
if do_color:
record.color_start = log.COLOR_START
record.color_end = log.COLOR_END
else:
record.color_start = record.color_end = ''
s = super(SatFormatter, self).format(record)
if self.with_colors and (self.can_colors or self.force_colors):
if do_color:
s = ConfigureStandard.ansiColors(record.levelname, s)
return s