Logging (C API)

emlearn has support for structured logging. This is primarily used internally, but may be used by applications.

A structured log entry consist of an event identifier, along with key/value pairs. An entry is serialized with logfmt:

event-name key1=value1 key2=value2\n

Structured logging has the following advantages:

  • Machine-readable. Easy to analyze with scripts

  • Event names should be unique and stable. Easy to search for

  • Indexable, including on particular keys/values. Can be merged with other data sources

Typical usage:

EML_LOG_BEGIN("my-event");
EML_LOG_ADD("key1", "string-value");
EML_LOG_ADD_INTEGER("key2", 123);
EML_LOG_ADD_BOOL("key3", true);
EML_LOG_ADD_FLOAT("key2", 3.14);
EML_LOG_END();

Defines

EML_LOG_ENABLE

Enable logging.

To enable #define EML_LOG_ENABLE 1 Default is OFF.

EML_LOG_PRINTF(...)
EML_LOG_PRINT_ARRAY(arr, len, fmt)
EML_LOG_BOOL_STR(b)
EML_LOG_BEGIN(eventname)

Start a log entry

EML_LOG_END()

End a log entry

EML_LOG_ADD(key, str)

Add a key/value pair (strings)

EML_LOG_ADD_INTEGER(key, integer)

Add an integer value

EML_LOG_ADD_BOOL(key, boolean)

Add a boolean value

EML_LOG_ADD_FLOAT(key, flt)

Add a floating-point value

EML_LOG_ADD_ARRAY(key, arr, len, fmt)

Add an array