summaryrefslogtreecommitdiffstats
path: root/pylog/onaplogging/mdcformatter.py
diff options
context:
space:
mode:
authorliangke <lokyse@163.com>2018-09-11 16:37:09 +0800
committerliangke <lokyse@163.com>2018-09-11 17:05:10 +0800
commite00f8c9d9fc89f3de7f324704b3bd02c976e21e9 (patch)
tree6c98c572bfb6e1f35bd9dd5f5aef7a06068d5a42 /pylog/onaplogging/mdcformatter.py
parent8dff758d560d3acdbd21a2ea11f4ba5a5ede1ff0 (diff)
Enable colored output for loggingLOG-380-shared
ColorFormatter class uses ANSI esacpe sequences to render logging message in color, it uses standard colors so it should workd on any UNIX terminal. Make markerFormatter class to inherits from colorFormatter. Change-Id: Ie24a06df861ca5d07796e78dea7e875daf149380 Issue-ID: MULTICLOUD-329 Signed-off-by: liangke <lokyse@163.com>
Diffstat (limited to 'pylog/onaplogging/mdcformatter.py')
-rw-r--r--pylog/onaplogging/mdcformatter.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/pylog/onaplogging/mdcformatter.py b/pylog/onaplogging/mdcformatter.py
index 087497d..74ff894 100644
--- a/pylog/onaplogging/mdcformatter.py
+++ b/pylog/onaplogging/mdcformatter.py
@@ -23,32 +23,33 @@ class MDCFormatter(MarkerFormatter):
to enrich log message.
"""
- def __init__(self, fmt=None, mdcfmt=None, datefmt=None, style="%"):
+ def __init__(self, fmt=None, mdcfmt=None,
+ datefmt=None, colorfmt=None, style="%"):
"""
:param fmt: build-in format string contains standard
Python %-style mapping keys
:param mdcFmt: mdc format with '{}'-style mapping keys
:param datefmt: Date format to use
+ :param colorfmt: colored output with ANSI escape code on terminal
:param style: style mapping keys in python3
"""
if sys.version_info > (3, 2):
- super(MDCFormatter, self).__init__(fmt=fmt, datefmt=datefmt,
+ super(MDCFormatter, self).__init__(fmt=fmt,
+ datefmt=datefmt,
+ colorfmt=colorfmt,
style=style)
elif sys.version_info > (2, 7):
- super(MDCFormatter, self).__init__(fmt=fmt, datefmt=datefmt)
+ super(MDCFormatter, self).__init__(fmt=fmt,
+ datefmt=datefmt,
+ colorfmt=colorfmt)
else:
- MarkerFormatter.__init__(self, fmt, datefmt)
+ MarkerFormatter.__init__(self, fmt, datefmt, colorfmt)
- self.style = style
self._mdc_tag = "%(mdc)s"
- if sys.version_info > (3, 2):
- if self.style not in logging._STYLES:
- raise ValueError('Style must be one of: %s' % ','.join(
- logging._STYLES.keys()))
- if self.style == "{":
- self._mdc_tag = "{mdc}"
- elif self.style == "$":
- self._mdc_tag = "${mdc}"
+ if self.style == "{":
+ self._mdc_tag = "{mdc}"
+ elif self.style == "$":
+ self._mdc_tag = "${mdc}"
if mdcfmt:
self._mdcFmt = mdcfmt