Skip to main content

mod_graylog2 — GELF Logging to Graylog

mod_graylog2 is a logger module (src/mod/loggers) that forwards FreeSWITCH log messages to a Graylog2 server over UDP using the Graylog Extended Log Format (GELF 1.1). Each log entry is serialised as a compact JSON object and dispatched asynchronously from a dedicated delivery thread, keeping the impact on the FreeSWITCH media path minimal.

Operators reach for this module when they need centralised, structured log aggregation from one or more FreeSWITCH nodes into Graylog2 (or a compatible receiver such as Logstash with the gelf.rb input). Session-specific channel variables can be automatically promoted to top-level GELF fields, which makes per-call filtering and alerting straightforward inside Graylog.

Loading the Module

The module name for load / unload is mod_graylog2. It is not enabled in the default vanilla load set — the entry in autoload_configs/modules.conf.xml is commented out:

<!-- <load module="mod_graylog2"/> -->

To activate it, uncomment that line (or add it) and restart FreeSWITCH, or load it at runtime:

freeswitch@> load mod_graylog2

No special build flags are required; the module compiles with the standard FreeSWITCH build system.

Configuration: graylog2.conf.xml

The module reads autoload_configs/graylog2.conf.xml at load time. All parameters live inside a <settings> element. An optional <fields> child element maps channel variables to additional GELF fields that are appended to every log message associated with a session.

ParameterPurposeAccepted ValuesDefault
server-hostIP address or hostname of the Graylog2 UDP listenerAny resolvable hostname or IP127.0.0.1
server-portUDP port of the Graylog2 GELF input16553512201
loglevelMinimum FreeSWITCH log level forwarded to Graylogdebug, info, notice, warning, err, crit, alert, emergwarning
send-uncompressed-headerPrepend the two-byte uncompressed GELF magic (\037\074) required by some Logstash GELF inputstrue / falsefalse

Within <fields>, each <field> element maps a GELF field name (the name attribute) to a FreeSWITCH channel variable (the variable attribute). The variable value is read from the active session at log time and added to the GELF object with a _ prefix, per the GELF custom-field convention.

<configuration name="graylog2.conf" description="Graylog2 Logger">
<settings>
<param name="server-host" value="192.168.0.69"/>
<param name="server-port" value="12201"/>
<param name="loglevel" value="warning"/>
<!-- Uncomment if using logstash w/ gelf.rb -->
<!--param name="send-uncompressed-header" value="true"/-->

<!-- fields to add to every log associated w/ a session -->
<fields>
<!-- channel variable "customer_account_number" becomes the "_customer" field -->
<!--field name="customer" variable="customer_account_number"/-->
</fields>
</settings>
</configuration>

GELF field mapping

The module emits GELF 1.1 objects. The fixed field names are:

GELF fieldContent
version"1.1"
hostFreeSWITCH hostname
timestampLog timestamp in Unix epoch seconds (converted from microseconds)
levelSyslog severity integer (1 alert → 7 debug; unmapped levels → 8)
short_messageFirst line of the log message
full_messageFull log message content
_ident"freeswitch"
_pidFreeSWITCH process ID
_uuidCall UUID (when log is associated with a session)
_fileSource file that generated the log
_lineSource line number
_functionSource function name
_sequenceLog sequence number
_microtimestampOriginal log timestamp in microseconds
_<name>Per-session fields declared in <fields>

Log messages exceeding 8192 bytes are silently dropped. The internal delivery queue holds up to 25 000 pending messages; entries that cannot be enqueued are discarded without blocking the caller.

Channel Variables

The module reads channel variables that are declared under <fields> in the configuration. There are no fixed, hard-coded variable names — the operator defines each mapping. For example, with:

<field name="customer" variable="customer_account_number"/>

the module reads customer_account_number from the active channel and adds _customer to the GELF object for every log line produced during that session.

Source: src/mod/loggers/mod_graylog2, conf/vanilla/autoload_configs/graylog2.conf.xml