aboutsummaryrefslogtreecommitdiffstats
path: root/pylog/onaplogging/markerFormatter.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/markerFormatter.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/markerFormatter.py')
-rw-r--r--pylog/onaplogging/markerFormatter.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/pylog/onaplogging/markerFormatter.py b/pylog/onaplogging/markerFormatter.py
index f33bfc2..c9b0628 100644
--- a/pylog/onaplogging/markerFormatter.py
+++ b/pylog/onaplogging/markerFormatter.py
@@ -16,32 +16,28 @@ import sys
import logging
from marker import MARKER_TAG
from marker import Marker
+from colorFormatter import BaseColorFormatter
-class MarkerFormatter(logging.Formatter):
+class MarkerFormatter(BaseColorFormatter):
- def __init__(self, fmt=None, datefmt=None, style='%'):
+ def __init__(self, fmt=None, datefmt=None, colorfmt=None, style='%'):
if sys.version_info > (3, 2):
super(MarkerFormatter, self).__init__(
- fmt=fmt, datefmt=datefmt, style=style)
+ fmt=fmt, datefmt=datefmt, colorfmt=colorfmt, style=style)
elif sys.version_info > (2, 7):
super(MarkerFormatter, self).__init__(
- fmt=fmt, datefmt=datefmt)
+ fmt=fmt, datefmt=datefmt, colorfmt=colorfmt)
else:
- logging.Formatter.__init__(self, fmt, datefmt)
+ BaseColorFormatter.__init__(self, fmt, datefmt, colorfmt)
- self.style = style
self._marker_tag = "%(marker)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._marker_tag = "{marker}"
- elif self.style == "$":
- self._marker_tag = "${marker}"
+ if self.style == "{":
+ self._marker_tag = "{marker}"
+ elif self.style == "$":
+ self._marker_tag = "${marker}"
self._tmpFmt = self._fmt
@@ -66,7 +62,7 @@ class MarkerFormatter(logging.Formatter):
if sys.version_info > (2, 7):
return super(MarkerFormatter, self).format(record)
else:
- return logging.Formatter.format(self, record)
+ return BaseColorFormatter.format(self, record)
finally:
self._fmt = self._tmpFmt