Skip to main content

Mdclogpy

Structured logging library with Mapped Diagnostic Context

  • Outputs the log entries to standard out in structured format, json currently.
  • Severity based filtering.
  • Supports Mapped Diagnostic Context (MDC). Set MDC pairs are automatically added to log entries by the library.

Log entry format

Each log entry written with mdclog_write() function contains

  • Timestamp
  • Logger identity
  • Log entry severity
  • All existing MDC pairs
  • Log message text

Currently the library only supports JSON formatted output written to standard out of the process.

Example log output

{"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!"}

Install

Install from PyPi

python3 -m pip install mdclogpy

Install using the source

python3 setup.py install

Usage

The library can be used in two ways shown below.

  1. Use the root logger
  import mdclogpy
  mdclogpy.mdclog_format_init(configmap_monitor=True) 
  mdclogpy.error("This is an error log")
  1. Create a logger instance
  from mdclogpy import Logger
  my_logger = Logger()
  my_logger.mdclog_format_init(configmap_monitor=True)
  my_logger.error("This is an error log")

A program can create several logger instances.

mdclog_format_init() Adds the MDC log format with HostName, PodName, ContainerName, ServiceName,PID,CallbackNotifyforLogFieldChange

Pass configmap_monitor = False in mdclog_format_init() function to stop dynamic log level change based on configmap.

Mapped Diagnostics Context

The MDCs are logger instance specific key-value pairs, which are included to all log entries written via the logger instance.

By default, the library implements a root logger instance. MDCs added to the root logger instance are added only to the log entries written via the root logger instance.

License

Copyright (c) 2019 AT&T Intellectual Property. Copyright (c) 2018-2019 Nokia.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This source code is part of the near-RT RIC (RAN Intelligent Controller) platform project (RICP).

Unit testing

To run the unit tests run the following command in the package directory:: python3 -m unittest discover

CI

The ci is done with the tox tool. See tox.ini file for details.

Release files for mdclogpy 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdclogpy 1.1.4
File Size Uploaded
mdclogpy-1.1.4.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdclogpy 1.1.4
File Interpreter ABI Platform
mdclogpy-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / mdclogpy-1.1.4.tar.gz

Download URL mdclogpy-1.1.4.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8d29bacda72d6b0098058bd3ff2317e8c9fccad99b3ecb774b5127451f9e7f1d
BLAKE2b-256 checksum
How to use checksums
809f4bf77736267be8a1ac9d1ea19dc973b0794185045f9614e7ea93d05230e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Release files / mdclogpy-1.1.4-py3-none-any.whl

Download URL mdclogpy-1.1.4-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5eca256996d66f263bdcdd0f2925280a664bcb0fe63d3ac6472a70385568b202
BLAKE2b-256 checksum
How to use checksums
24c90d03c30cb3316529dbd4fcd2a2b6dfd9982244dee3fc63259b4efffbe0b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page