Being a daemon application, Kamailio logging capabilities are very flexible, from ability to write your own log messages via configuration file script, to controlling the log levels via RPC, enable logging only for specific modules (see debugger module), log latency values, dump the execution trace or the list of variables to the log backend and many more…

The log backends can be also selected via command line parameters or by using specific modules: writing to terminal, to syslog, systemd or sending the log messages via UDP to a configurable address.

The latest addition to the logging features (introduced a few weeks ago) is the ability to write the log messages as a structured JSON document. Instead of having the classic style of line-based plain text messages, the new feature builds a JSON document from the attributes that compose the log message. This can be enabled by using –log-engine command line parameter.

For example, the classic style log messages printed to terminal can look like:

1(18282) DEBUG: {1 1 OPTIONS 286030750@192.168.188.20} maxfwd [mf_funcs.c:74]: is_maxfwd_present(): value = 70

1(18282) DEBUG: {1 1 OPTIONS 286030750@192.168.188.20} <core> [core/socket_info.c:644]: grep_sock_info(): checking if host==us: 9==9 && [127.0.0.1] == [127.0.0.1]

With structured JSON logging, the same logs printed to terminal look like:

{ "idx": 1, "pid": 18239, "level": "DEBUG", "module": "maxfwd", "file": "mf_funcs.c", "line": 74, "function": "is_maxfwd_present", "logprefix": "{1 1 OPTIONS 715678756@192.168.188.20} ", "message": "value = 70 " }

{ "idx": 1, "pid": 18239, "level": "DEBUG", "module": "core", "file": "core/socket_info.c", "line": 644, "function": "grep_sock_info", "logprefix": "{1 1 OPTIONS 715678756@192.168.188.20} ", "message": "checking if host==us: 9==9 && [127.0.0.1] == [127.0.0.1]" }

For the later, kamailio was started with:

kamailio --log-engine=json:M ...

More details about the –log-engine parameter can be found at:

Having the logs in JSON document could make the processing easier, especially when using indexing and search platforms such as ELK stack.

Enjoy!

Stay safe and healthy! Thanks for flying Kamailio!