Fix osdf code after upgrading to py38
[optf/osdf.git] / osdf / logging / oof_mdc_formatter.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2020 AT&T Intellectual Property
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16 # -------------------------------------------------------------------------
17 #
18
19 import time
20
21 from onaplogging.colorFormatter import RESET
22 from onaplogging.mdcformatter import MDCFormatter
23
24
25 class OOFMDCFormatter(MDCFormatter):
26     """ONAP MDC formatter
27
28     """
29
30     def __init__(self, fmt=None, mdcfmt=None,
31                  datefmt=None, colorfmt=None, style="%"):
32         super().__init__(fmt, mdcfmt, datefmt, colorfmt, style)
33         self.converter = time.gmtime
34
35     def _replaceStr(self, keys):
36         """overriding the default behavior
37
38         keys: keys that needs to be substituted
39
40         """
41         fmt = self._mdcFmt
42         for i in keys:
43             fmt = fmt.replace(i, i)
44
45         return fmt
46
47     def format(self, record):
48         """Removing the color format end of line character.
49
50         """
51         return super(OOFMDCFormatter, self).format(record).replace(RESET, '')