2 .. Copyright (c) 2019 AT&T Intellectual Property.
4 .. Copyright (c) 2019 Nokia.
7 .. Licensed under the Creative Commons Attribution 4.0 International
9 .. Public License (the "License"); you may not use this file except
11 .. in compliance with the License. You may obtain a copy of the License at
14 .. https://creativecommons.org/licenses/by/4.0/
17 .. Unless required by applicable law or agreed to in writing, documentation
19 .. distributed under the License is distributed on an "AS IS" BASIS,
21 .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 .. See the License for the specific language governing permissions and
25 .. limitations under the License.
27 .. This source code is part of the near-RT RIC (RAN Intelligent Controller)
29 .. platform project (RICP).
36 Clone the pylog git repository
37 ------------------------------
40 git clone "https://gerrit.o-ran-sc.org/r/com/pylog"
43 Mapped Diagnostics Context
44 --------------------------
46 The MDCs are logger instance specific key-value pairs, which are included to
47 all log entries written via the logger instance.
49 By default, the library implements a root logger instance.
50 MDCs added to the root logger instance are added only to the log entries
51 written via the root logger instance.
56 Each log entry written with mdclog_write() function contains
61 * All existing MDC pairs
64 Currently the library only supports JSON formatted output written to standard
69 `{"ts": 1603103945651, "crit": "ERROR", "id": "test.py", "mdc": {"PID":101,"SYSTEM_NAME": "Cloud-Space", "HOST_NAME": "master", "SERVICE_NAME": "TestApp", "CONTAINER_NAME": "Container-101", "POD_NAME": "POD-101"}, "msg": "Hello World!"}`
77 python3 -m pip install mdclogpy
79 Install using the source
83 python3 setup.py install
88 The library can be used in two ways shown below.
90 1) Use the root logger
96 mdclogpy.mdclog_format_init(configmap_monitor=True)
97 mdclogpy.error("This is an error log")
100 2) Create a logger instance
105 from mdclogpy import Logger
107 my_logger.mdclog_format_init(configmap_monitor=True)
108 my_logger.error("This is an error log")
111 A program can create several logger instances.
113 mdclog_format_init() Adds the MDC log format with HostName, PodName, ContainerName, ServiceName,PID,CallbackNotifyforLogFieldChange
115 Pass configmap_monitor = False in mdclog_format_init() function to stop dynamic log level change based on configmap.
121 """Severity levels of the log messages."""
130 1. Set current logging level
134 def set_level(self, level: Level):
137 level -- logging level. Log messages with lower severity will be filtered.
139 2. Return the current logging level
143 def get_level(self) -> Level:
145 3. Add a logger specific MDC
149 def add_mdc(self, key: str, value: Value):
155 4. Return logger's MDC value with the given key or None
159 def get_mdc(self, key: str) -> Value:
161 5. Remove logger's MDC with the given key
165 def remove_mdc(self, key: str):
167 6. Remove all MDCs of the logger instance.
174 7. Initialise Logging format:
176 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.
181 def mdclog_format_init(configmap_monitor=False):
184 configmap_monitor -- Enables/Disables Dynamic log level change based on configmap
185 -- Boolean values True/False can be passed as per requirement.
192 Copyright (c) 2019 AT&T Intellectual Property.
193 Copyright (c) 2018-2019 Nokia.
195 Licensed under the Apache License, Version 2.0 (the "License");
196 you may not use this file except in compliance with the License.
197 You may obtain a copy of the License at
199 http://www.apache.org/licenses/LICENSE-2.0
201 Unless required by applicable law or agreed to in writing, software
202 distributed under the License is distributed on an "AS IS" BASIS,
203 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
204 See the License for the specific language governing permissions and
205 limitations under the License.
207 This source code is part of the near-RT RIC (RAN Intelligent Controller)
208 platform project (RICP).
213 To run the unit tests run the following command in the package directory
217 python3 -m unittest discover