Tuesday, October 14, 2014

Kamailio 4.2 Tips: #1 - Log message prefix

Quite long time since I haven't posted here on technical subjects related to Kamailio. Being just around the corner of a new major version release, 4.2.0, I am going to have a small series of short posts to reveal some of the new tiny bits that can improve a lot your experience managing Kamailio.

Tip #1 - global parameter: log_prefix

It can be used to specify the text to be prefixed to each log message printed by Kamailio while processing the SIP message.

An immediate benefit could be for log messages added in kamailio.cfg via xlog module functions. If you want to match the log message with packets from a network trace, you have to print several details from SIP packet. For example, such list of details can be:
  • sip message type
  • source ip
  • sequence number
  • sip method type
  • call-id
In addition, the xlog message would have some extra text to describing its role.

With older versions, that was possible by listing those elements in each xlog, like:

xlog("$mt $si $cs $rm $ci - extra text one\n");
xlog("$mt $si $cs $rm $ci - extra text two\n");

With 4.2, it can be done like:

log_prefix="$mt $si $cs $rm $ci - "
...
xlog("extra text one\n");
xlog("extra text two\n");

An useful effect is that log messages printed from inside the C code will be prefixed as well. Many of the error messages in C code don't print any details of the SIP message processed at that moment, now you can overcome it without touching the C code.

As a bonus, remember that you can have different log level for core and each of loaded modules by using debugger module and setting the appropriate mod_level parameter, even in v4.1.x.

Enjoy it!

No comments:

Post a Comment