4 Structured logging library with Mapped Diagnostic Context
6 * Outputs the log entries to standard out in structured format, json currently.
7 * Severity based filtering.
8 * Supports Mapped Diagnostic Context (MDC).
9 Set MDC pairs are automatically added to log entries by the library.
15 Each log entry written with mdclog_write() function contains
20 * All existing MDC pairs
23 Currently the library only supports JSON formatted output written to standard
28 `{"ts": 1603103945651, "crit": "ERROR", "id": "test.py", "mdc": {"PID":101,"SYSTEM_NAME": "Cloud-Space", "HOST_NAME": "master", "SERVICE_NAME": "TestApp", "CONTAINER_NAME": "", "POD_NAME": ""}, "msg": "Hello World!"}`
37 python3 -m pip install mdclogpy
40 Install using the source
43 python3 setup.py install
49 The library can be used in two ways shown below.
51 1) Use the root logger
55 mdclogpy.mdclog_format_init(configmap_monitor=True)
56 mdclogpy.error("This is an error log")
59 2) Create a logger instance
62 from mdclogpy import Logger
64 my_logger.mdclog_format_init(configmap_monitor=True)
65 my_logger.error("This is an error log")
68 A program can create several logger instances.
70 mdclog_format_init() Adds the MDC log format with HostName, PodName, ContainerName, ServiceName,PID,CallbackNotifyforLogFieldChange
72 Pass configmap_monitor = False in mdclog_format_init() function to stop dynamic log level change based on configmap.
75 Mapped Diagnostics Context
76 --------------------------
78 The MDCs are logger instance specific key-value pairs, which are included to
79 all log entries written via the logger instance.
81 By default, the library implements a root logger instance.
82 MDCs added to the root logger instance are added only to the log entries
83 written via the root logger instance.
89 Copyright (c) 2019 AT&T Intellectual Property.
90 Copyright (c) 2018-2019 Nokia.
92 Licensed under the Apache License, Version 2.0 (the "License");
93 you may not use this file except in compliance with the License.
94 You may obtain a copy of the License at
96 http://www.apache.org/licenses/LICENSE-2.0
98 Unless required by applicable law or agreed to in writing, software
99 distributed under the License is distributed on an "AS IS" BASIS,
100 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101 See the License for the specific language governing permissions and
102 limitations under the License.
104 This source code is part of the near-RT RIC (RAN Intelligent Controller)
105 platform project (RICP).
110 To run the unit tests run the following command in the package directory::
112 python3 -m unittest discover
118 The ci is done with the `tox` tool. See `tox.ini` file for details.