Developer Guide

Log repo location

git clone ""


  • gcc > version 4

  • autoconf

  • gawk

  • libtool

  • automake

  • make

  • pkg-config

  • autoconf-archive

  • libjsoncpp-dev

  • gcc-c++

  • doxygen

Compilation uses GNU autotools



Installation is done using command make install. Installation directory can be set with the configure options –prefix and –libdir before compilation. Optionally the root can be set with DESTDIR=<my root dir> argument to the make install command.

Example Log

{"timestamp":1550045469,"severity":"INFO","logger":"applicationABC", "mdc":{"key1":"value1","key2":"value2"}, "message": "This is an example log"}
{"ts":1602081593063,"crit":"INFO","id":"myapp","mdc":{"PID":"21587","POD_NAME":"tta-app-5565fc4d6f-ppfl8","CONTAINER_NAME":"tta-app","SERVICE_NAME":"TEST_APP","HOST_NAME":"master-an","SYSTEM_NAME":"CloudSpace-0"},"msg":"This is an example log"}

Using the library

Example usage

#include <mdclog/mdclog.h>

void init_log()
   int log_change_monitor = 1;
   mdclog_attr_t *attr;
   mdclog_attr_set_ident(attr, "myapp");
      mdclog_write(MDCLOG_ERR, "Failed to intialize MDC log format !!!");

int main()
   mdclog_mdc_add("mykey", "keyval");
   mdclog_mdc_add("second key", "other value");
   mdclog_write(MDCLOG_INFO, "hello world!");


The library should be taken to C code compilation with the pkg-config. The library installation installs also the corresponding .pc file under the library directory. If pkg-config does not find the mdclog .pc file, you should set environment variable PKG_CONFIG_PATH poiting to the installation directory. For example, if the installation prefix was /home/username/mdclog then set the environment variable like this export PKG_CONFIG_PATH=/home/username/mdclog/lib/pkgconfig.

CFLAGS=$(pkg-config mdclog -cflags)
LIBS=$(pkg-config mdclog -libs)

gcc myapp.c $CFLAGS $LIBS -o myapp

Log API’s

  1. Init MDC Configuration

int mdclog_init(mdclog_attr_t *attr)
  1. MDC Log Write

void mdclog_write(mdclog_severity_t severity, const char *format, ...)
  1. Set MDC Log level

void mdclog_level_set(mdclog_severity_t level)
  1. Get MDC Log level

mdclog_severity_t mdclog_level_get(void)
  1. Initialise the MDC log attributes

int mdclog_attr_init(mdclog_attr_t **attr)
  1. Clean-up the MDC Log attributes

void mdclog_attr_destroy(mdclog_attr_t *attr)
  1. Set MDC Log identity

int mdclog_attr_set_ident(mdclog_attr_t *attr, const char *identity)
  1. Add Key-Value in MDC Log

int mdclog_mdc_add(const char *key, const char *value)
  1. Remove Key-Value from MDC Log

void mdclog_mdc_remove(const char *key)
  1. Get Value of the Key from MDC Log

char *mdclog_mdc_get(const char *key)
  1. Cleanup the MDC Log instance

void mdclog_mdc_clean(void)

12. Initialzes mdclog print format using MDC Array 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.

Note: In K8s/Docker Containers the environment variables are declared in the Helm charts.

Refer xAPP developer guide for more information about how to define Helm chart.

int mdclog_format_initialize(const int log_change_monitor);

Unit testing

Unit testing is executed using make check or make test commands.

Continuous Integration

The supplied Dockerfile defines an image that builds and tests this library for continuous integration (CI) purposes such as a Jenkins job.

Code coverage report

Enable unit test gcov code coverage analysis by configuring gcov reporting directory:

configure --with-gcov-report-dir=DIR

Directory can be an absolute path or a relative path to an log source root. Unit test build creates directory if it does not exist.

Build and run unit tests with code coverage analysis:

make test_gcov

After successful unit test run code coverage (.gcov) result files are in a directory, what was defined by –with-gcov-report-dir configure option.

In addition, graphical gcov front-ends such as lcov can be used for coverage analysis:

lcov --directory tst/ --directory src --capture --output-file
genhtml --output-directory out

Open the out/index.html using any web browser.

Binary package creation

Debian and RPM packages can be generated with the script. To make debian (.dep) packages you need to install

  • devscripts

  • debhelper

and run

./ debian
To make RPM packages you need to install
  • rpm-build

and run

./ rpm

Docker Tests

It’s also possible to test compilation, run unit tests and test building of rpm and Debian packages in a Docker:

docker build  --no-cache -f docker_test/Dockerfile-Test -t logtest:latest

If needed, ready rpm and Debian packages can be copied from Docker to host.In below example packages are copied to host’s /tmp/logtest-packages directory:

docker run -v /tmp/logtest-packages:/export logtest:latest /export