4. Admin Log Methods

Admins can write log messages from configuration file. This eases the troubleshooting and monitoring of the system.

Typically, OpenSER is configured to issue a message to the syslog on errors or extraordinary situations of which the system administrator should be notified. The format of the logs is loose, depending on the type of event being reported. Usually the situation is described by one or two sentences and some processing data is logged as well when available.

OpenSER core exports a method to log plain text messages while a module (xlog) allow writing more complex log messages based on specifiers.

4.1. Simple Log Messages

In addition to the log messages issued by OpenSER internally, the administrators can configure OpenSER to write more log messages using the “log” method explicitly in configuration file. The prototype of the method is:

log([level,] message)

The meaning of the parameters:

  • level - an integer value specifying the log level

  • message - the message to write in logs. It does not support specifiers, the message will be printed as it is.

If no log level is specified, the messages are issued at log level 4 (L_DBG).

Example 1. Logging example

...
log("This is a log message\n");
log(1, "This is another log message\n");
...

4.2. Formatted Log Messages

To print formatted log messages from OpenSER configuration script, one can use “xlog” module. The module exports two functions that allow to use specifiers which will be replaced with an appropriate value when printing the message. An specifier for printing has the same format and meaning as pseudo-variable (http://www.openser.org/docs/pseudo-variables.html);

Complete documentation of this module and its facilities can be found in module's “README” file located in sip_router/modules/xlog directory.

Example 2. Logging with xlog

...
xdbg("SIP Request: method [$rm] from [$fu] to [$tu]\n");
xlog("L_INFO", "SIP Request: method [$rm] from [$fu] to [$tu]\n");
...