106. Configuration
An NXLog configuration consists of global directives, module instances, and routes. The following sections list the core NXLog directives provided. Additional directives are provided at the module level.
A valid configuration must contain at least one input module instance and at least one output module instance. If no route is specified, a route will be automatically generated; this route will connect all input module instances and all output module instances in a single path.
A module instance name may contain letters, digits, periods (.
), and
underscores (_
). The first character in a module instance name must
be a letter or an underscore. The corresponding regular expression is
[a-zA-Z_][a-zA-Z0-9._]*
.
A route instance name may contain letters, digits, periods (.
), and
underscores (_
). The first character in a route instance name must be
a letter, a digit, or an underscore. The corresponding regular expression is
[a-zA-Z0-9_][a-zA-Z0-9._]*
.
106.1. General Directives
The following directives can be used throughout the configuration file. These directives are handled by the configuration parser, and substitutions occur before the configuration check.
- define
-
Use this directive to configure a constant or macro to be used later. Refer to a
define
by surrounding the name with percent signs (%
). Enclose a group of statements with curly braces ({}
).Example 431. Using the define DirectiveThis configuration shows three example defines:
BASEDIR
is a constant,IMPORTANT
is a statement, andWARN_DROP
is a group of statements.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
define BASEDIR /var/log define IMPORTANT if $raw_event =~ /important/ \ $Message = 'IMPORTANT ' + $raw_event; define WARN_DROP { log_warning("dropping message"); drop(); } <Input messages> Module im_file File '%BASEDIR%/messages' </Input> <Input proftpd> Module im_file File '%BASEDIR%/proftpd.log' <Exec> %IMPORTANT% if $raw_event =~ /dropme/ %WARN_DROP% </Exec> </Input>
- envvar
-
This directive works like define, except that the value is retrieved from the environment.
Example 432. Using the envvar DirectiveThis example is like the previous one, but
BASEDIR
is fetched from the environment instead.
- include
-
This directive allows a specified file to be included in the current configuration file. Wildcarded filenames are supported.
NoteThe SpoolDir directive only takes effect after the configuration is parsed, so relative paths specified with the include directive must be relative to the working directory NXLog was started from. Example 433. Using the include DirectiveThis example includes a file relative to the directory NXLog is started from:
nxlog.conf1
include modules/module1.conf
This example includes all matching files and uses an absolute path:
nxlog.conf1
include /etc/nxlog.d/*.conf
- include_stdout
-
This directive accepts the name of an external command or script. Configuration content will be read from the command’s standard output. Command arguments are not supported.
Example 434. Using the include_stdout DirectiveThis directive executes the custom script, which fetches the configuration.
nxlog.conf1
include_stdout /opt/nxset/etc/fetch_conf.sh
106.2. Global Directives
- CacheDir
-
This directive specifies a directory where the cache file (
configcache.dat
) should be written. This directive has a compiled-in value which is used by default.
- CacheFlushInterval
-
This directive specifies how often the in-memory position cache should be flushed to the cache file. The value of 0 indicates that the cache should only be flushed to the file when the agent shuts down; if the server or agent crashes, the current position cache will be lost. A positive integer indicates the length of the interval between flushes of the cache, in seconds. The string
always
specifies that the cache should be flushed to file immediately when a module sets a value. If this directive is not specified the default value of 5 seconds is used. See also the CacheSync directive below.
- CacheSync
-
When the in-memory position cache is flushed to the cache file, the cache may not be immediately written to the disk due to filesystem buffering. When this directive is set to TRUE, the cache file is synced to disk immediately when it is written. The default is FALSE. CacheSync has no effect if CacheFlushInterval is set to the default of 0. Setting this to TRUE when CacheFlushInterval is set to
always
greatly reduces performance, though only this guarantees crash-safe operation.
- DateFormat
-
This directive can be used to change the default date format as it appears in the LogFile, in the
$raw_event
generated by the modules, and when a datetime type value is converted to a string. The following values are accepted (corresponding to the formats accepted by the NXLog strftime() function):-
YYYY-MM-DD hh:mm:ss
(the default) -
YYYY-MM-DDThh:mm:ssTZ
-
YYYY-MM-DDThh:mm:ss.sTZ
-
YYYY-MM-DD hh:mm:ssTZ
-
YYYY-MM-DD hh:mm:ss.sTZ
-
YYYY-MM-DDThh:mm:ssUTC
-
YYYY-MM-DDThh:mm:ss.sUTC
-
YYYY-MM-DD hh:mm:ssUTC
-
YYYY-MM-DD hh:mm:ss.sUTC
-
A format string accepted by the strftime() function in the C library
-
- FlowControl
-
This optional boolean directive specifies the flow control default for input and processor module instances. Output module instances do not inherit from this directive. By default, the global FlowControl value is TRUE. See the description of the module level FlowControl directive for more information.
- GenerateDateInUTC
-
If set to TRUE, this boolean directive specifies that UTC should be used when generating dates in the format
YYYY-MM-DD hh:mm:ss
. If set to FALSE, local time will be used when generating dates in this format. The default is FALSE. See also ParseDateInUTC.
- Group
-
Similar to User, NXLog will set the group ID to run under. The group can be specified by name or numeric ID. This directive has no effect when running on the Windows platform or with nxlog-processor(8).
- IgnoreErrors
-
If set to FALSE, NXLog will stop when it encounters a problem with the configuration file (such as an invalid module directive) or if there is any other problem which would prevent all modules functioning correctly. If set to TRUE, NXLog will start after logging the problem. The default value is TRUE.
- LogFile
-
NXLog will write its internal log to this file. If this directive is not specified, self logging is disabled. Note that the im_internal module can also be used to direct internal log messages to files or different output destinations, but this does not support log level below
INFO
. This LogFile directive is especially useful for debugging.
- LogLevel
-
This directive has five possible values:
CRITICAL
,ERROR
,WARNING
,INFO
, andDEBUG
. It will set both the logging level used for LogFile and the standard output if NXLog is started in the foreground. The default LogLevel isINFO
.
- LogqueueDir
-
This directive specifies the directory where the files of the persistent queues are stored, for Processor and Output module instances. Even if PersistLogqueue is set to FALSE, NXLog will persist in-memory queues to the LogqueueDir on shutdown. If not specified, the default is the value of CacheDir. This directive can also be used at the module level to specify a log queue directory for a specific module instance.
- LogqueueSize
-
This directive controls the size of the log queue for all Processor and Output module instances. The default is 100 records. See the module-level LogQueueSize for more information.
- ModuleDir
-
By default the NXLog binaries have a compiled-in value for the directory to search for loadable modules. This can be overridden with this directive. The module directory contains sub-directories for each module type (extension, input, output, and processor), and the module binaries are located in those.
- NoCache
-
Some modules save data to a cache file which is persisted across a shutdown/restart. Modules such as im_file will save the file position in order to continue reading from the same position after a restart as before. This caching mechanism can be explicitly turned off with this directive. This is mostly useful with nxlog-processor(8) in offline mode. If this boolean directive is not specified, it defaults to FALSE (caching is enabled). Note that many input modules, such as im_file, provide a SavePos directive that can be used to disable the position cache for a specific module instance. SavePos has no effect if the cache is disabled globally with
NoCache TRUE
.
- NoFreeOnExit
-
This directive is for debugging. When set to TRUE, NXLog will not free module resources on exit, allowing valgrind to show proper stack trace locations in module function calls. The default value is FALSE.
- Panic
-
A panic condition is a critical state which usually indicates a bug. Assertions are used in NXLog code for checking conditions where the code will not work unless the asserted condition is satisfied, and for security. Failing assertions result in a panic and suggest a bug in the code. A typical case is checking for NULL pointers before pointer dereference. This directive can take three different values:
HARD
,SOFT
, orOFF
.HARD
will cause an abort in case the assertion fails. This is how most C based programs work.SOFT
will cause an exception to be thrown at the place of the panic/assertion. In case of NULL pointer checks this is identical to a NullPointerException in Java. It is possible that NXLog can recover from exceptions and can continue to process log messages, or at least the other modules can. In case of assertion failure the location and the condition is printed atCRITICAL
log level inHARD
mode andERROR
log level inSOFT
mode. If Panic is set toOFF
, the failing condition is printed in the logs but the execution will continue on the normal code path. Most of the time this will result in a segmentation fault or other undefined behavior, though in some cases turning off a buggy assertion or panic will solve the problems caused by it inHARD
/SOFT
mode. The default value for Panic isSOFT
.
- ParseDateInUTC
-
If set to TRUE, this boolean directive specifies that dates in the format
YYYY-MM-DD hh:mm:ss
should be parsed as UTC. If set to FALSE, dates in this format are assumed to be in local time. The default is FALSE. See also GenerateDateInUTC.
- PersistLogqueue
-
This boolean directive specifies that log queues of Processor and Output module instances should be disk-based. See the module level PersistLogqueue directive for more information.
- PidFile
-
Under Unix operating systems, NXLog writes a PID file as other system daemons do. The default PID file can be overridden with this directive in case multiple daemon instances need to be running. This directive has no effect when running on the Windows platform or with nxlog-processor(8).
- ReadTimeout
-
This directive is specific to nxlog-processor(8). It controls the exit condition of nxlog-processor(8). Its value is a timeout in seconds. If nxlog-processor(8) gets no data to process during this period then it will stop waiting for more data and will exit. The default value is 0.05 s. For any non-negative value which is less than 0.05 this will be 0.05. In case nxlog-processor(8) is configured to read data from the network it is recommended to set this to higher value.
- RootDir
-
NXLog will set its root directory to the value specified with this directive. If SpoolDir is also set, this will be relative to the value of RootDir (chroot() is called first). This directive has no effect when running on the Windows platform or with the nxlog-processor(8).
- SpoolDir
-
NXLog will change its working directory to the value specified with this directive. This is useful with files created through relative filenames (for example, with om_file) and in case of core dumps. This directive has no effect with the nxlog-processor(8).
- StringLimit
-
To protect against memory exhaustion (and possibly a denial-of-service) caused by over-sized strings, there is a limit on the length of each string (in bytes). The default value is 5242880 bytes (strings will be truncated at 5 MiB).
- SuppressRepeatingLogs
-
Under some circumstances it is possible for NXLog to generate an extreme amount of internal logs consisting of the same message due to an incorrect configuration or a software bug. In this case, the LogFile can quickly consume the available disk space. With this directive, NXLog will write at most 2 lines per second if the same message is generated successively, by logging "last message repeated n times" messages. If this boolean directive is not specified, it defaults to TRUE (suppression of repeating messages is enabled).
- SyncLogqueue
-
When this directive is set to TRUE and PersistLogqueue is enabled, the disk-based queues of Processor and Output module instances will be immediately synced after each new entry is added to the queue. This greatly reduces performance but makes the queue more reliable and crash-safe. This directive can also be used at the module level.
- Threads
-
This directive specifies the number of worker threads to use. The number of the worker threads is calculated and set to an optimal value if this directive is not defined. Do not set this unless you know what you are doing.
- User
-
NXLog will drop to the user specified with this directive. This is useful if NXLog needs privileged access to some system resources (such as kernel messages or to bind a port below 1024). On Linux systems NXLog will use capabilities to access these resources. In this case NXLog must be started as root. The user can be specified by name or numeric ID. This directive has no effect when running on the Windows platform or with nxlog-processor(8).
106.3. Common Module Directives
The following directives are common to all modules. The Module directive is mandatory.
- Module
-
This mandatory directive specifies which binary should be loaded. The module binary has a
.so
extension on Unix and a.dll
on Windows platforms and resides under the ModuleDir location. Each module binary name is prefixed withim_
,pm_
,om_
, orxm_
(for input, processor, output, and extension, respectively). It is possible for multiple instances to use the same loadable binary. In this case the binary is only loaded once but instantiated multiple times. Different module instances may have different configurations.
- BufferSize
-
This directive specifies the size of the read or write buffer (in bytes) used by the Input or Output module, respectively. The BufferSize directive is only valid for Input and Output module instances. The default buffer size is 65000 bytes.
- FlowControl
-
This optional boolean directive specifies whether the module instance should use flow control. FlowControl is only valid for input, processor, and output modules. For input and processor modules, the FlowControl default is inherited from the global FlowControl directive (which defaults to TRUE). To maintain backward compatibility, the FlowControl default for output modules is TRUE regardless of the global FlowControl value.
Under normal conditions, when all module instances are operating normally and buffers are not full, flow control has no effect. However, if a module becomes blocked and is unable to process events, flow control will automatically suspend module instances as necessary to prevent events from being lost. For example, consider a route with im_file and om_tcp. If a network error blocks the output, NXLog will stop reading events from file until the network error is resolved. If flow control is disabled, NXLog will continue reading from file and processing events; the events will be discarded when passed to the output module.
In most cases, flow control should be left enabled, but it may be necessary to disable it in certain scenarios. It is recommended to leave flow control enabled globally and only specify the FlowControl directive in two cases. First, set
FlowControl FALSE
on any input module instance that should never be suspended. Second, if a route contains multiple output instances, it may be desirable to continue sending events to other outputs even if one output becomes blocked—setFlowControl FALSE
on the output(s) where events can be discarded to prevent the route from being blocked.Internally, flow control takes effect when the log queue of the next module instance in the route becomes full. If flow control is enabled, the instance suspends. If flow control is disabled, events are discarded. If the next module in the route is an output module, both FlowControl values are consulted—flow control is enabled only if both are TRUE.
WarningSuspending an im_linuxaudit instance could cause an Audit backlog, blocking processes that generate Audit messages. Suspending an im_udp instance is ineffective, because UDP provides no receipt acknowledgement. Suspending an im_uds instance when collecting local Syslog messages from the /dev/log Unix domain socket will cause the syslog() system call to block in any programs trying to write to the system log. It is generally recommended to disable flow control in these cases.
- InputType
-
This directive specifies the name of the registered input reader function to be used for parsing raw events from input data. Names are treated case insensitively. This directive is only available for stream oriented input modules: im_file, im_exec, im_ssl, im_tcp, im_udp, and im_uds. These modules work by filling an input buffer with data read from the source. If the read operation was successful (there was data coming from the source), the module calls the specified callback function. If this is not explicitly specified, the module default will be used. Note that im_udp may only work properly if log messages do not span multiple packets and are within the UDP message size limit. Otherwise the loss of a packet may lead to parsing errors.
Modules may provide custom input reader functions. Once these are registered into the NXLog core, the modules listed above will be capable of using these. This makes it easier to implement custom protocols because these can be developed without concern for the transport layer.
The following input reader functions are provided by the NXLog core:
- Binary
-
The input is parsed in the NXLog binary format, which preserves the parsed fields of the event records. The LineBased reader will automatically detect event records in the binary NXLog format, so it is only recommended to configure InputType to Binary if compatibility with other logging software is not required.
- Dgram
-
Once the buffer is filled with data, it is considered to be one event record. This is the default for the im_udp input module, since UDP Syslog messages arrive in separate packets.
- LineBased
-
The input is assumed to contain event records separated by newlines. It can handle both CRLF (Windows) and LF (Unix) line-breaks. Thus if an LF (
\n
) or CRLF (\r\n
) is found, the function assumes that it has reached the end of the event record. If the input begins with the UTF-8 byte order mark (BOM) sequence (0xEF,0xBB,0xBF
), that sequence is automatically skipped.
Example 435. TCP Input Assuming NXLog FormatThis configuration explicitly specifies the Binary InputType.
- LogqueueDir
-
This directive specifies the directory where the files of the persistent queue are stored. LogqueueDir is only valid for Processor and Output module instances. See the description of the global LogqueueDir for more information.
- LogqueueSize
-
Every Processor and Output instance has an input log queue for events waiting to be processed by that module. The size of the queue is measured in event records, and can be set with this directive—the default is 100 records. When the log queue of a module instance is full and FlowControl is enabled for the preceeding module, the preceeding module will be suspended. If flow control is not enabled for the preceeding module, events will be discarded. This directive is only valid for Processor and Output module instances. This directive can be used at the global level to affect all modules.
- OutputType
-
This directive specifies the name of the registered output writer function to be used for formatting raw events when storing or forwarding output. Names are treated case insensitively. This directive is only available for stream oriented output modules: om_file, om_exec, om_ssl, om_tcp, om_udp, and om_uds. These modules work by filling the output buffer with data to be written to the destination. The specified callback function is called before the write operation. If this is not explicitly specified, the module default will be used.
Modules may provide custom output formatter functions. Once these are registered into the NXLog core, the modules listed above will be capable of using these. This makes it easier to implement custom protocols because these can be developed without concern for the transport layer.
The following output writer functions are provided by the NXLog core:
- Binary
-
The output is written in the NXLog binary format which preserves parsed fields of the event records.
- Dgram
-
Once the buffer is filled with data, it is considered to be one event record. This is the default for the om_udp output module, since UDP Syslog messages are sent in separate packets.
- LineBased
-
The output will contain event records separated by newlines. The record terminator is CRLF (
\r\n
) on Windows and LF (\n
) on Unix.
- LineBased_CRLF
-
The output will contain event records separated by Windows style newlines where the record terminator is CRLF (
\r\n
).
- LineBased_LF
-
The output will contain event records separated by Unix style newlines where the record terminator is LF (
\n
).
Example 436. TCP Output Sending Messages in NXLog FormatThis configuration explicitly specifies the Binary OutputType.
- PersistLogqueue
-
When a module passes an event to the next module along the route, it puts it into the next module’s queue. This queue can be either a memory-based or disk-based (persistent) queue. When this directive is set to TRUE, the module will use a persistent (disk-based) queue. With the default value of FALSE, the module’s incoming log queue will not be persistent (will be memory-based); however, in-memory log queues will still be persisted to disk on shutdown. This directive is only valid for Processor and Output module instances. This directive can also be used at the global level.
- SyncLogqueue
-
When this directive is set to TRUE and PersistLogqueue is enabled, the disk-based queue will be immediately synced after each new entry is added to the queue. This greatly reduces performance but makes the queue more reliable and crash-safe. This directive is only valid for Processor and Output module instances. This directive can be used at the global level to affect all modules.
106.3.1. Exec
The Exec directive/block contains statements in the NXLog language which are executed when a module receives a log message. This directive is available in all input, processor, and output modules. It is not available in most extension modules because these do not handle log messages directly (the xm_multiline and xm_rewrite modules do provide Exec directives).
This statement assigns a value to the $Hostname
field in the event
record.
1
Exec $Hostname = 'myhost';
Each directive must be on one line unless it contains a trailing
backslash (\
) character.
This if statement uses line continuation to span multiple lines.
More than one Exec directive or block may be specified. They are executed in the order of appearance. Each Exec directive must contain a full statement. Therefore it is not possible to split the lines in the previous example into multiple Exec directives. It is only possible to split the Exec directive if it contains multiple statements.
This example shows two equivalent uses of the Exec directive.
1
2
Exec log_info("first"); \
log_info("second");
This produces identical behavior:
1
2
Exec log_info("first");
Exec log_info("second");
The Exec directive can also be used as a block. To use multiple
statements spanning more than one line, it is recommended to use the
<Exec>
block instead. When using a block, it is not necessary to use
the backslash (\
) character for line continuation.
106.3.2. Schedule
The Schedule block can be used to execute periodic jobs, such as log rotation or any other task. Scheduled jobs have the same priority as the module. The Schedule block has the following directives:
- Every
-
In addition to the crontab format it is possible to schedule execution at periodic intervals. With the crontab format it is not possible to run a job every five days for example, but this directive enables it in a simple way. It takes a positive integer value with an optional unit. The unit can be one of the following:
sec
,min
,hour
,day
, orweek
. If the unit is not specified, the value is assumed to be in seconds. The Every directive cannot be used in combination withRunCount 1
.
- Exec
-
The mandatory Exec directive takes one or more NXLog statements. This is the code which is actually being scheduled. Multiple Exec directives can be specified within one Schedule block. See the module-level Exec directive, this behaves the same. Note that it is not possible to use fields in statements here because execution is not triggered by log messages.
- First
-
This directive sets the first execution time. If the value is in the past, the next execution time is calculated as if NXLog has been running since and jobs will not be run to make up for missed events in the past. The directive takes a datetime literal value.
- RunCount
-
This optional directive can be used to specify a maximum number of times that the corresponding Exec statement(s) should be executed. For example, with
RunCount 1
the statement(s) will only be executed once.
- When
-
This directive takes a value similar to a crontab entry: five space-separated definitions for minute, hour, day, month, and weekday. See the crontab(5) manual for the field definitions. It supports lists as comma separated values and/or ranges. Step values are also supported with the slash. Month and week days are not supported, these must be defined with numeric values. The following extensions are also supported:
@startup Run once when NXLog starts. @reboot (Same as @startup) @yearly Run once a year, "0 0 1 1 *". @annually (Same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once a week, "0 0 * * 0". @daily Run once a day, "0 0 * * *". @midnight (Same as @daily) @hourly Run once an hour, "0 * * * *".
106.4. Route Directives
The following directives can be used in Route blocks. The Path directive is mandatory.
- Path
-
The data flow is defined by the Path directive. First the instance names of Input modules are specified. If more than one Input reads log messages which feed data into the route, then these must be separated by commas. The list of Input modules is followed by an arrow (
=>
). Either processor modules or output modules follow. Processor modules must be separated by arrows, not commas, because they operate in series, unlike Input and Output modules which work in parallel. Output modules are separated by commas. The Path must specify at least an Input and an Output. The syntax is illustrated by the following:Path INPUT1[, INPUT2...] => [PROCESSOR1 [=> PROCESSOR2...] =>] OUTPUT1[, OUTPUT2...]
Example 442. Specifying RoutesThe following configuration shows modules being used in two routes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<Input in1> Module im_null </Input> <Input in2> Module im_null </Input> <Processor p1> Module pm_null </Processor> <Processor p2> Module pm_null </Processor> <Output out1> Module om_null </Output> <Output out2> Module om_null </Output> <Route 1> # Basic route Path in1 => out1 </Route> <Route 2> # Complex route with multiple input/output/processor modules Path in1, in2 => p1 => p2 => out1, out2 </Route>
- Priority
-
This directive takes an integer value in the range of 1-100 as a parameter, and the default is
10
. Log messages in routes with a lower Priority value will be processed before others. Internally, this value is assigned to each module part of the route. The events of the modules are processed in priority order by the NXLog engine. Modules of a route with a lower Priority value (higher priority) will process log messages first.Example 443. Prioritized ProcessingThis configuration prioritizes the UDP route over the TCP route in order to minimize loss of UDP Syslog messages when the system is busy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<Input tcpin> Module im_tcp Host localhost Port 514 </Input> <Input udpin> Module im_udp Host localhost Port 514 </Input> <Output tcpfile> Module om_file File "/var/log/tcp.log" </Output> <Output udpfile> Module om_file File "/var/log/udp.log" </Output> <Route udp> Priority 1 Path udpin => udpfile </Route> <Route tcp> Priority 2 Path tcpin => tcpfile </Route>