Functions
A function is an expression which returns a value. The returned value can be used to set fields, output log data, or make logic decisions. Functions can be polymorphic, meaning that the same function can take different argument types.
Many NXLog language features are provided through functions. As with other types of expressions, and unlike procedures, functions do not modify the state of the NXLog engine, the state of the module, or the current event.
See the list of available core functions. Modules can provide additional functions for use with the NXLog language.
These expressions call the now() function to return
the current time and the hostname() function to
return the hostname of the system where NXLog is installed. The returned
values are used to set the $EventTime
and $Relay
fields.
$EventTime = now();
$Relay = hostname();
In the example below, the size() function is called to
calculate the size of the $Message
field. If the field is over 4096 bytes,
an internal log is generated.
if size($Message) > 4096 log_info('Large message received.');
Functions for a specific module instance can be called using the ->
operator. This expression calls the file_name() and
file_size() functions of an om_file instance named
out
. The returned values are used to log the name and size of its current
output file.
log_info('Size of output file ' + out->file_name() + ' is ' + out->file_size());
Calling functions of a specific instance is especially useful when the
configuration contains more than one instance of the same module. These
expressions call the to_xml() function of two xm_xml
instances, one named xml_a
and the other named xml_b
.
xml_a->to_xml();
xml_b->to_xml();