nglogc is a flexible C logging API, it is released under the LGPL license. The author, Dennis Krzyzaniak, has released a full detailed manual.

In the following lines, the first two paragraphs from the manual, just to understand something about this library.


Logging is a powerful mechanism to obtain runtime information from software components (programs). These information can be of different types: transaction logs for audit purposes, logs for error detection or detailed debug information for error analysis. Also, the more the source code is growing the harder it gets to have an idea on exactly which place an error occurs or if the program has the correct chain of activity without any log for verification.

There are already tons of examples running everywhere, which make use of logging and also many logging packages are available in the public. However, it can still be found very often, that developers start to use a debugger or add some printf-kind statements to their code in case they run into trouble with software, which is not working as expected.

The difference between an audit trace and a debug log is that the first might be wanted in a productional environment while the latter might be required only during error analysis and should not influence normal operation. It might also be wanted to ouput the one information into a file while the other should go onto the display or to some other device.

But one is equal for all kind of information: they are different levels of information from a software component which may be routed to different destinations.

The intention of the nglogc library is to provide an easy to use and powerful logging API with mechanism which allows to cram source codes with log statements at the start of implementation and decide at the level of building or at runtime which statements should be processed.

Therefore the log statements could be controlled by various log levels and define switches are available to completely remove the call of the functions at pre-processor time. So it is possible to switch on the logging only if it is necessary or only print selected messages without any changes in the source code. Different publishers are provided also as different formats of outputs to fulfil the requirements for software development.

Simple example

This simple example shows a short way to use nglogc for logging.

At first a logger which is identified by an uint16_t type must be registered with a associated log level and publisher. Three different basic log functions are available, error logging, info logging and data array logging. Because a logger uses memory of the heap a remove function should be called at the end of the programm.

#include <nglogc/log.h>

/* loggers are identified by an uint16_t type */

#define MAIN_LOGGER 0x0001

/* example error code */

#define EXAMPLE_ERR 0x00000001

int main(int argc, char *argv[])


int i = 0;

unsigned char data[16] = {0};

/* register a logger with the stdout publisher and

LOG_BASIC log level */

logc_registerLogger(MAIN_LOGGER, STDOUT, LOG_BASIC);

/* fill some test data */

for (i=0; i<sizeof(data); i++) {

data[i] = 'A' + i;


/* log an error message with the log level LOG_BASIC */


"This is a error message");

/* log an info message with the log level LOG_BASIC */


"This is a log message");

/* log an data array in hex with description */


"Data array", data, sizeof(data));

/* remove the logger */


return 0;


The output of this example is:

ERR : This is a error message

This is a log message

Data array : 4142434445464748494A4B4C4D4E4F50

Last but not least, you can find the package at this address: nglogc