rsyslog

rsyslog is a syslog implementation that offers many benefits over syslog-ng. It can be configured to receive log entries from systemd's journal in order to process or filter them before quickly writing them to disk or sending them over network.

Installation

Note: It is recommended to disable and uninstall the syslog-ng package to prevent possible conflicts.

Install the rsyslogAUR package.

Starting service

You can start/enable rsyslog.service after installation.

Configure hostname

Rsyslog uses the glibc routine gethostname() or gethostbyname() to determine the hostname of the local machine. The gethostname() or gethostbyname() routine check the contents of for the fully qualified domain name (FQDN) if you are not using BIND or NIS.

You can check what the local machine's currently configured FQDN is by running . The output of will be used by rsyslog when writing log messages. If you want to have full hostnames in logs, you need to add to the beginning of the file (before using any directive that write to files). This is because, rsyslog reads its configuration file and applies it on-the-go and then reads the later lines.

The file contains a number of lines that map FQDNs to IP addresses and that map aliases to FQDNs. See the example file below:

/etc/hosts
#<ip-address>    <hostname.domain.org> <hostname>
#<ip-address>    <actual FQDN> <aliases>
127.0.0.1        localhost.localdomain somehost.localdomain localhost somehost
::1              localhost.localdomain somehost.localdomain localhost somehost

localhost.localdomain is the first item following the IP address, so gethostbyname() function will return localhost.localdomain as the local machine's FQDN. Then file will use localhost as hostname.

To use somehost as the hostname. Move somehost.localdomain to the first item:

Configuration

rsyslog is configured in . See the official documentation for more information on the available configuration options.

By default, all syslog messages are handled by systemd's journal. In order to gather system logs in rsyslog, you either have to turn on #journald's syslog-forward feature or use the #imjournal module of rsyslog to gather the logs by importing it from the systemd journald.

imjournal

If you want rsyslog to pull messages from systemd, load the imjournal module:

See the documentation on the imjournal input module for more information.

journald's syslog-forward feature

The rsyslogAUR does not create its working directory defined by the variable in the configuration file. You might need to create it manually or change its destination.

Log output can be fine tuned in . The daemon uses Facility levels (see below) to determine what gets put where. For example:

States that all messages falling under the authpriv facility are logged to /var/log/secure.

Another example, which would be similar to the behaviour of syslog-ng for the old :

See Systemd/Journal#Journald in conjunction with syslog for more information.

Facility levels

Facility NumberKeywordFacility Description
0kernkernel messages
1useruser-level messages
2mailmail system
3daemonsystem daemons
4authsecurity/authorization messages
5syslogmessages generated internally by syslogd
6lprline printer subsystem
7newsnetwork news subsystem
8uucpUUCP subsystem
9clock daemon
10authprivsecurity/authorization messages
11ftpFTP daemon
12-NTP subsystem
13-log audit
14-log alert
15cronclock daemon
16local0local use 0 (local0)
17local1local use 1 (local1)
18local2local use 2 (local2)
19local3local use 3 (local3)
20local4local use 4 (local4)
21local5local use 5 (local5)
22local6local use 6 (local6)
23local7local use 7 (local7)

Severity levels

As defined in RFC 5424, there are eight severity levels:

CodeSeverityKeywordDescriptionGeneral Description
0Emergencyemerg (panic)System is unusable.A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
1AlertalertAction must be taken immediately.Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection.
2CriticalcritCritical conditions.Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
3Errorerr (error)Error conditions.Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
4Warningwarning (warn)Warning conditions.Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time.
5NoticenoticeNormal but significant condition.Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required.
6InformationalinfoInformational messages.Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
7DebugdebugDebug-level messages.Info useful to developers for debugging the application, not useful during operations.
Tip: A common mnemonic used to remember the syslog levels in reverse order: "Do I Notice When Evenings Come Around Early".

Examples

journald with rsyslog for kernel messages

Since the syslog component of systemd, journald, does not flush its logs to disk during normal operation, these logs will be gone when the machine is shut down abnormally (power loss, kernel lock-ups, ...). In the case of kernel lock-ups, it can be important to have some kernel logs for debugging. Until journald gains a configuration option for flushing kernel logs, rsyslog can be used in conjunction with journald.

Summary of requirements:

  • journald must still get all log messages.
  • rsyslog must only log kernel messages, all other logs are handled by journald.
  • Kernel logs must be logged separatedly to .
  • Use systemd to start the service.

Installation and configuration steps:

  1. Install rsyslogAUR.
  2. Edit and add to the list of logs. Without this modification, the kernel log would grow indefinitely.
  3. Edit and comment everything except for . If a heart-beat (repeated confirmation that the log is alive) is preferred, should remain uncommented as well.
  4. Add the next line to the same configuration file:
    The kern.* part catches all messages originating from the kernel. is used here to use a less verbose date format. By default, a date format like is used. Since the kernel log contains a precision already (printk time) and the actual log time is irrelevant, a format like might be preferred.
  5. Since rsyslog should operate completely separated from systemd, remove the option that shares a socket with systemd:
  6. Next, make rsyslog start on boot and start it for this session by starting and enabling rsyslog.service.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.