Mercurial > libervia-backend
comparison src/core/log.py @ 2154:7cbffd754b4a
core (constants), tools (common/ansi): moved ANSI escape codes to a dedicated class, with helper methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Feb 2017 00:44:54 +0100 |
parents | 7f053e1f0b67 |
children | 8b37a62336c3 |
comparison
equal
deleted
inserted
replaced
2153:f67434fd88d2 | 2154:7cbffd754b4a |
---|---|
20 """High level logging functions""" | 20 """High level logging functions""" |
21 # XXX: this module use standard logging module when possible, but as SàT can work in different cases where logging is not the best choice (twisted, pyjamas, etc), it is necessary to have a dedicated module. Additional feature like environment variables and colors are also managed. | 21 # XXX: this module use standard logging module when possible, but as SàT can work in different cases where logging is not the best choice (twisted, pyjamas, etc), it is necessary to have a dedicated module. Additional feature like environment variables and colors are also managed. |
22 # TODO: change formatting from "%s" style to "{}" when moved to Python 3 | 22 # TODO: change formatting from "%s" style to "{}" when moved to Python 3 |
23 | 23 |
24 from sat.core.constants import Const as C | 24 from sat.core.constants import Const as C |
25 from sat.tools.common.ansi import ANSI as A | |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
26 | 27 |
27 backend = None | 28 backend = None |
28 _loggers = {} | 29 _loggers = {} |
29 handlers = {} | 30 handlers = {} |
233 taint_list = levels_taints_dict.get(level, C.LOG_OPT_TAINTS_DICT[1][level]) | 234 taint_list = levels_taints_dict.get(level, C.LOG_OPT_TAINTS_DICT[1][level]) |
234 ansi_list = [] | 235 ansi_list = [] |
235 for elt in taint_list: | 236 for elt in taint_list: |
236 elt = elt.upper() | 237 elt = elt.upper() |
237 try: | 238 try: |
238 ansi = getattr(C, 'ANSI_FG_{}'.format(elt)) | 239 ansi = getattr(A, 'FG_{}'.format(elt)) |
239 except AttributeError: | 240 except AttributeError: |
240 try: | 241 try: |
241 ansi = getattr(C, 'ANSI_{}'.format(elt)) | 242 ansi = getattr(A, elt) |
242 except AttributeError: | 243 except AttributeError: |
243 # we use raw string if element is unknown | 244 # we use raw string if element is unknown |
244 ansi = elt | 245 ansi = elt |
245 ansi_list.append(ansi) | 246 ansi_list.append(ansi) |
246 taints[level] = ''.join(ansi_list) | 247 taints[level] = ''.join(ansi_list) |
316 except KeyError: | 317 except KeyError: |
317 start = '' | 318 start = '' |
318 | 319 |
319 if cls._color_location: | 320 if cls._color_location: |
320 return message % {'color_start': start, | 321 return message % {'color_start': start, |
321 'color_end': C.ANSI_RESET} | 322 'color_end': A.RESET} |
322 else: | 323 else: |
323 return '%s%s%s' % (start, message, C.ANSI_RESET) | 324 return '%s%s%s' % (start, message, A.RESET) |
324 | 325 |
325 @staticmethod | 326 @staticmethod |
326 def getProfile(): | 327 def getProfile(): |
327 """Try to find profile value using introspection""" | 328 """Try to find profile value using introspection""" |
328 raise NotImplementedError | 329 raise NotImplementedError |