core (log/standard backend): added "%(profile)s" format management

This commit is contained in:
Goffi 2014-05-05 20:16:13 +02:00
commit 2802250596

View file

@ -189,6 +189,8 @@ def _getProfile():
current_path = stack[0][1]
for frame_data in stack[:-1]:
if frame_data[1] != current_path:
if _backend == C.LOG_BACKEND_STANDARD and "/logging/__init__.py" in frame_data[1]:
continue
break
frame = frame_data[0]
@ -200,7 +202,10 @@ def _getProfile():
try:
profile = args.locals['self'].profile
except AttributeError:
profile = args.locals['self'].parent.profile
try:
profile = args.locals['self'].parent.profile
except AttributeError:
profile = args.locals['self'].host.profile # used in quick_frontend for single profile configuration
except Exception:
# we can't find profile, we return an empty value
profile = ''
@ -555,12 +560,15 @@ class ConfigureStandard(Configure):
class SatFormatter(logging.Formatter):
u"""Formatter which manage SàT specificities"""
_format = fmt
_with_profile = '%(profile)s' in fmt
def __init__(self, can_colors=False):
super(SatFormatter, self).__init__(self._format)
self.can_colors = can_colors
def format(self, record):
if self._with_profile:
record.profile = _getProfile()
s = super(SatFormatter, self).format(record)
if self.with_colors and (self.can_colors or self.force_colors):
s = _ansiColors(record.levelname, s)