NAME
rsyslog.conf - rsyslogd(8) configuration fileDESCRIPTION
The rsyslog.conf file is the main configuration file for the rsyslogd(8) which logs system messages on *nix systems. This file specifies rules for logging. For special features see the rsyslogd(8) manpage. Rsyslog.conf is backward-compatible with sysklogd's syslog.conf file. So if you migrate from sysklogd you can rename it and it should work.MODULES
Rsyslog has a modular design. Consequently, there is a growing number of modules. See the HTML documentation for their full description.- omsnmp
- SNMP trap output module
- omgssapi
- Output module for GSS-enabled syslog
- ommysql
- Output module for MySQL
- omrelp
- Output module for the reliable RELP protocol (prevents message loss). For details, see below at imrelp and the HTML documentation. It can be used like this:
- *.* :omrelp:server:port
- *.* :omrelp:192.168.0.1:2514 # actual sample
- ompgsql
- Output module for PostgreSQL
- omlibdbi
- Generic database output module (Firebird/Interbase, MS SQL, Sybase, SQLite, Ingres, Oracle, mSQL)
- imfile
- Input module for text files
- imudp
- Input plugin for UDP syslog. Replaces the deprecated -r option. Can be used like this:
- $ModLoad imudp
- $UDPServerRun 514
- imtcp
- Input plugin for plain TCP syslog. Replaces the deprecated -t option. Can be used like this:
- $ModLoad imtcp
- $InputTCPServerRun 514
- imrelp
- Input plugin for the RELP protocol. RELP can be used instead of UDP or plain TCP syslog to provide reliable delivery of syslog messages. Please note that plain TCP syslog does NOT provide truly reliable delivery, with it messages may be lost when there is a connection problem or the server shuts down. RELP prevents message loss in those cases. It can be used like this:
- $ModLoad imrelp
- $InputRELPServerRun 2514
- imgssapi
- Input plugin for plain TCP and GSS-enable syslog
- immark
- Support for mark messages
- imklog
- Kernel logging. To include kernel log messages, you need to do
- $ModLoad imklog Please note that the klogd daemon is no longer necessary and consequently no longer provided by the rsyslog package.
- imuxsock
- Unix sockets, including the system log socket. You need to specify
- $ModLoad imuxsock in order to receive log messages from local system processes. This config directive should only left out if you know exactly what you are doing.
BASIC STRUCTURE
Lines starting with a hash mark ('#') and empty lines are ignored. Rsyslog.conf should contain following sections (sorted by recommended order in file):- Global directives
- Global directives set some global properties of whole rsyslog daemon, for example size of main message queue ($MainMessageQueueSize), loading external modules ($ModLoad) and so on. All global directives need to be specified on a line by their own and must start with a dollar-sign. The complete list of global directives can be found in HTML documentation in doc directory or online on web pages.
- Templates
- Templates allow you to specify format of the logged message. They are also used for dynamic file name generation. They have to be defined before they are used in rules. For more info about templates see TEMPLATES section of this manpage.
- Output channels
- Output channels provide an umbrella for any type of output that the user might want. They have to be defined before they are used in rules. For more info about output channels see OUTPUT CHANNELS section of this manpage.
- Rules (selector + action)
- Every rule line consists of two fields, a selector field and an action field. These two fields are separated by one or more spaces or tabs. The selector field specifies a pattern of facilities and priorities belonging to the specified action.
SELECTORS
The selector field itself again consists of two parts, a facility and a priority, separated by a period ('.'). Both parts are case insensitive and can also be specified as decimal numbers, but don't do that, you have been warned. Both facilities and priorities are described in syslog(3). The names mentioned below correspond to the similar LOG_-values in /usr/include/syslog.h.ACTIONS
The action field of a rule describes what to do with the message. In general, message content is written to a kind of "logfile". But also other actions might be done, like writing to a database table or forwarding to another host.Regular file
Typically messages are logged to real files. The file has to be specified with full pathname, beginning with a slash ('/').*.*
/var/log/traditionalfile.log;RSYSLOG_TraditionalFileFormat # log to a file in
the traditional format
*.* /var/log/file.log # log to a file with
RFC3339 timestamps
Named pipes
This version of rsyslogd(8) has support for logging output to named pipes (fifos). A fifo or named pipe can be used as a destination for log messages by prepending a pipe symbol ('|') to the name of the file. This is handy for debugging. Note that the fifo must be created with the mkfifo(1) command before rsyslogd(8) is started.Terminal and console
If the file you specified is a tty, special tty-handling is done, same with /dev/console.Remote machine
There are three ways to forward message: the traditional UDP transport, which is extremely lossy but standard, the plain TCP based transport which loses messages only during certain situations but is widely available and the RELP transport which does not lose messages but is currently available only as part of rsyslogd 3.15.0 and above.*.* @192.168.0.1
action(type="omfwd"
Target="192.168.0.1" Device="eth0" Port=514
Protocol="udp")
*.* :omrelp:192.168.0.1:2514
List of users
Usually critical messages are also directed to ``root'' on that machine. You can specify a list of users that shall get the message by simply writing ":omusrmsg:" followed by the login name. You may specify more than one user by separating them with commas (','). If they're logged in they get the message (for example: ":omusrmsg:root,user1,user2").Everyone logged on
Emergency messages often go to all users currently online to notify them that something strange is happening with the system. To specify this wall(1)-feature use an ":omusrmsg:*".Database table
This allows logging of the message to a database table. By default, a MonitorWare-compatible schema is required for this to work. You can create that schema with the createDB.SQL file that came with the rsyslog package. You can also use any other schema of your liking - you just need to define a proper template and assign this template to the action.Discard
If the discard action is carried out, the received message is immediately discarded. Discard can be highly effective if you want to filter out some annoying messages that otherwise would fill your log files. To do that, place the discard actions early in your log files. This often plays well with property-based filters, giving you great freedom in specifying what you do not want.*.* stop # discards everything.
Output channel
Binds an output channel definition (see there for details) to this action. Output channel actions must start with a $-sign, e.g. if you would like to bind your output channel definition "mychannel" to the action, use "$mychannel". Output channels support template definitions like all all other actions.Shell execute
This executes a program in a subshell. The program is passed the template-generated message as the only command line parameter. Rsyslog waits until the program terminates and only then continues to run.^program-to-execute;template
FILTER CONDITIONS
Rsyslog offers three different types "filter conditions":* "traditional" severity and facility based selectors
* property-based filters
* expression-based filters
Selectors
Selectors are the traditional way of filtering syslog messages. They have been kept in rsyslog with their original syntax, because it is well-known, highly effective and also needed for compatibility with stock syslogd configuration files. If you just need to filter based on priority and facility, you should do this with selector lines. They are not second-class citizens in rsyslog and offer the best performance for this job.Property-Based Filters
Property-based filters are unique to rsyslogd. They allow one to filter on any property, like HOSTNAME, syslogtag and msg.:property, [!]compare-operation,
"value"
contains
isequal
startswith
regex
Checks if the string provided in value is
contained in the property
Compares the "value" string provided
and the property contents. These two values must be exactly equal to
match.
Checks if the value is found exactly at the
beginning of the property value
Compares the property against the provided
regular expression.
Expression-Based Filters
See the HTML documentation for this feature.TEMPLATES
Every output in rsyslog uses templates - this holds true for files, user messages and so on. Templates compatible with the stock syslogd formats are hardcoded into rsyslogd. If no template is specified, we use one of these hardcoded templates. Search for "template_" in syslogd.c and you will find the hardcoded ones.$template MyTemplateName,"\7Text
%property% some more text\n",<options>
% = \%
\ = \\ --> '\' is used to escape (as in C)
$template
DynFile,"/var/log/system-%HOSTNAME%.log"
Template options
The <options> part is optional. It carries options influencing the template as whole. See details below. Be sure NOT to mistake template options with property options - the later ones are processed by the property replacer and apply to a SINGLE property, only (and not the whole template).- sql
- format the string suitable for a SQL statement in MySQL format. This will replace single quotes ("'") and the backslash character by their backslash-escaped counterpart ("´" and "\") inside each field. Please note that in MySQL configuration, the NO_BACKSLASH_ESCAPES mode must be turned off for this format to work (this is the default).
- stdsql
- format the string suitable for a SQL statement that is to be sent to a standards-compliant sql server. This will replace single quotes ("'") by two single quotes ("''") inside each field. You must use stdsql together with MySQL if in MySQL configuration the NO_BACKSLASH_ESCAPES is turned on.
Template examples
Please note that the samples are split across multiple lines. A template MUST NOT actually be split across multiple lines.$template
TraditionalFormat,"%timegenerated% %HOSTNAME%
%syslogtag%%msg:::drop-last-lf%\n"
$template
precise,"%syslogpriority%,%syslogfacility%,%timegenerated%,%HOSTNAME%,
%syslogtag%,%msg%\n"
$template
RFC3164fmt,"<%PRI%>%TIMESTAMP% %HOSTNAME%
%syslogtag%%msg%"
$template usermsg,"
XXXX%syslogtag%%msg%\n\r"
$template wallmsg,"\r\n\7Message from
syslogd@%HOSTNAME% at %timegenerated%"
$template MySQLInsert,"insert iut,
message, receivedat values ('%iut%', '%msg:::UPPERCASE%',
'%timegenerated:::date-mysql%') into systemevents\r\n", SQL
NOTE 1: This template is embedded into core application under name
StdDBFmt , so you don't need to define it.
NOTE 2: You have to have MySQL module installed to use this template.
OUTPUT CHANNELS
Output Channels are a new concept first introduced in rsyslog 0.9.0. As of this writing, it is most likely that they will be replaced by something different in the future. So if you use them, be prepared to change you configuration file syntax when you upgrade to a later release.$outchannel
name,file-name,max-size,action-on-max-size
*.* :omfile:$mychannel
PROPERTY REPLACER
The property replacer is a core component in rsyslogd's output system. A syslog message has a number of well-defined properties (see below). Each of this properties can be accessed and manipulated by the property replacer. With it, it is easy to use only part of a property value or manipulate the value, e.g. by converting all characters to lower case.Accessing Properties
Syslog message properties are used inside templates. They are accessed by putting them between percent signs. Properties can be modified by the property replacer. The full syntax is as follows:%propname:fromChar:toChar:options%
Available Properties
- msg
- the MSG part of the message (aka "the message" ;))
- rawmsg
- the message exactly as it was received from the socket. Should be useful for debugging.
- HOSTNAME
- hostname from the message
- FROMHOST
- hostname of the system the message was received from (in a relay chain, this is the system immediately in front of us and not necessarily the original sender)
- syslogtag
- TAG from the message
- programname
- the "static" part of the tag, as defined by BSD syslogd. For example, when TAG is "named[12345]", programname is "named".
- PRI
- PRI part of the message - undecoded (single value)
- PRI-text
- the PRI part of the message in a textual form (e.g. "syslog.info")
- IUT
- the monitorware InfoUnitType - used when talking to a MonitorWare backend (also for phpLogCon)
- syslogfacility
- the facility from the message - in numerical form
- syslogfacility-text
- the facility from the message - in text form
- syslogseverity
- severity from the message - in numerical form
- syslogseverity-text
- severity from the message - in text form
- timegenerated
- timestamp when the message was RECEIVED. Always in high resolution
- timereported
- timestamp from the message. Resolution depends on what was provided in the message (in most cases, only seconds)
- TIMESTAMP
- alias for timereported
- PROTOCOL-VERSION
- The contents of the PROTOCOL-VERSION field from IETF draft draft-ietf-syslog-protocol
- STRUCTURED-DATA
- The contents of the STRUCTURED-DATA field from IETF draft draft-ietf-syslog-protocol
- APP-NAME
- The contents of the APP-NAME field from IETF draft draft-ietf-syslog-protocol
- PROCID
- The contents of the PROCID field from IETF draft draft-ietf-syslog-protocol
- MSGID
- The contents of the MSGID field from IETF draft draft-ietf-syslog-protocol
- $NOW
- The current date stamp in the format YYYY-MM-DD
- $YEAR
- The current year (4-digit)
- $MONTH
- The current month (2-digit)
- $DAY
- The current day of the month (2-digit)
- $HOUR
- The current hour in military (24 hour) time (2-digit)
- $MINUTE
- The current minute (2-digit)
Character Positions
FromChar and toChar are used to build substrings. They specify the offset within the string that should be copied. Offset counting starts at 1, so if you need to obtain the first 2 characters of the message text, you can use this syntax: "%msg:1:2%". If you do not wish to specify from and to, but you want to specify options, you still need to include the colons. For example, if you would like to convert the full message text to lower case, use "%msg:::lowercase%". If you would like to extract from a position until the end of the string, you can place a dollar-sign ("$") in toChar (e.g. %msg:10:$%, which will extract from position 10 to the end of the string).Property Options
Property options are case-insensitive. Currently, the following options are defined:- uppercase
- convert property to lowercase only
- lowercase
- convert property text to uppercase only
- drop-last-lf
- The last LF in the message (if any), is dropped. Especially useful for PIX.
- date-mysql
- format as mysql date
- date-rfc3164
- format as RFC 3164 date
- date-rfc3339
- format as RFC 3339 date
- escape-cc
- replace control characters (ASCII value 127 and values less then 32) with an escape sequence. The sequence is "#<charval>" where charval is the 3-digit decimal value of the control character. For example, a tabulator would be replaced by "#009".
- space-cc
- replace control characters by spaces
- drop-cc
- drop control characters - the resulting string will neither contain control characters, escape sequences nor any other replacement character like space.
QUEUED OPERATIONS
Rsyslogd supports queued operations to handle offline outputs (like remote syslogd's or database servers being down). When running in queued mode, rsyslogd buffers messages to memory and optionally to disk (on an as-needed basis). Queues survive rsyslogd restarts.FILES
- /etc/rsyslog.conf
- Configuration file for rsyslogd
SEE ALSO
rsyslogd(8), logger(1), syslog(3)AUTHORS
rsyslogd is taken from sysklogd sources, which have been heavily modified by Rainer Gerhards ([email protected]) and others.22 October 2012 | Version 7.2.0 |