2 .. Copyright (c) 2019 AT&T Intellectual Property.
4 .. Copyright (c) 2019 Nokia.
6 .. Copyright (c) 2021 Samsung
8 .. Licensed under the Creative Commons Attribution 4.0 International
10 .. Public License (the "License"); you may not use this file except
12 .. in compliance with the License. You may obtain a copy of the License at
15 .. https://creativecommons.org/licenses/by/4.0/
18 .. Unless required by applicable law or agreed to in writing, documentation
20 .. distributed under the License is distributed on an "AS IS" BASIS,
22 .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 .. See the License for the specific language governing permissions and
26 .. limitations under the License.
28 .. This source code is part of the near-RT RIC (RAN Intelligent Controller)
30 .. platform project (RICP).
40 The library can be used in as shown below.
46 from ricappframe.logger.mdclogger import MDCLogger
47 my_logger = MDCLogger()
48 my_logger.mdclog_format_init(configmap_monitor=True)
49 my_logger.error("This is an error log")
52 A program can create several logger instances.
54 mdclog_format_init() Adds the MDC log format with HostName, PodName, ContainerName, ServiceName,PID,CallbackNotifyforLogFieldChange
56 Pass configmap_monitor = False in mdclog_format_init() function to stop dynamic log level change based on configmap.
62 """Severity levels of the log messages."""
71 1. Set current logging level
75 def set_level(self, level: Level):
78 level -- logging level. Log messages with lower severity will be filtered.
80 2. Return the current logging level
84 def get_level(self) -> Level:
86 3. Add a logger specific MDC
90 def add_mdc(self, key: str, value: Value):
96 4. Return logger's MDC value with the given key or None
100 def get_mdc(self, key: str) -> Value:
102 5. Remove logger's MDC with the given key
106 def remove_mdc(self, key: str):
108 6. Remove all MDCs of the logger instance.
115 7. Initialise Logging format:
117 This api Initialzes mdclog print format using MDC Dictionary by extracting the environment variables in the calling process for “SYSTEM_NAME”, “HOST_NAME”, “SERVICE_NAME”, “CONTAINER_NAME”, “POD_NAME” & “CONFIG_MAP_NAME” mapped to HostName, ServiceName, ContainerName, Podname and Configuration-file-name of the services respectively.
122 def mdclog_format_init(configmap_monitor=False):
125 configmap_monitor -- Enables/Disables Dynamic log level change based on configmap
126 -- Boolean values True/False can be passed as per requirement.