# &adminguide;

## Overview

It provides logging to systemd journal from the moment of loading this module.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- none.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- libsystemd

## Core Logging

This module can replace the syslog logging with sending the log messages to systemd journal. The logging to systemd is started when this module is loaded, before that the default syslog system is used.

It requires that core parameters log_engine_type to be set to 'systemd'. It is not enabled if log_stderror=yes.

### `Core Logging Replacement with Systemd`

    ...
    log_engine_type="systemd"
    ...
    loadmodule "log_systemd.so"
    ...

## Functions

### `sd_journal_print(level, text)`

Print the text in the systemd journal at the provided level parameter.

Both parameters can contain variables.

For more, see the manual page for function sd_journal_print() in C library libsystemd.

This function can be used from ANY_ROUTE.

#### `sd_journal_print` usage

    ...
       sd_journal_print("LOG_INFO", "R-URI is $ru\n");
    ...

### `sd_journal_send_xavp(name)`

Creates a structured log event in journald.

The sd_journal_send_xavp(name) function sends a log event in journald, based on the fields provided in the xavp whose root name is specified as parameter. This function is a wrapper for journald's sd_journal_send() function, and allows to specify as many custom fields as desired (see sd_journal_send(3)).

The xavp given as parameter must contain child AVPs with names conforming to journald's field name policy (only uppercase letters, numbers and underscore), otherwise they will be discarded by journald.

Some field name have a default meaning for journald:

- MESSAGE: the human-readable message string for this entry.

- PRIORTTY: integer priority value between 0 ("emerg") and 7 ("debug")

- (...) (see systemd.journald-fields(7))

This function can be used from ANY_ROUTE.

#### `sd_journal_send_xavp` usage

    request_route {
        $xavp(event=>MESSAGE) = $rm + " request logged with journald";
        $xavp(event[0]=>SIP_MESSAGE) = $mb;
    # don't forget the '[0]', otherwise kamailio will create and
    # stack new AVPs (see pseudovariable documentation) over the previous one
        $xavp(event[0]=>SIP_CALL_ID) = $ci;
        $xavp(event[0]=>SIP_SRC_PORT) = $sp;
        $xavp(event[0]=>PRIORITY) = 6;
        sd_journal_send_xavp("event");
    (...)
    }