Skip to content

Linux Foundations / Manage a Linux host ยท Step 42 of 50

Lesson: syslogSwitch
โ† Linux Foundations

System administration

syslog

Understand syslog facilities and severities, rsyslog rules and the logger command.

Syslog is a long-standing standard for log messages. Programs send messages to a syslog service, which decides where they go. The message format is described in RFC 5424, and the older BSD style in RFC 3164. On Linux the service is often rsyslog.

Facility and severity

Every message carries two labels. The facility says what kind of source it is: kern, user, mail, daemon, auth, authpriv, cron, and local0 to local7 for your own use.

The severity says how serious it is. From most to least serious:

| Number | Name | |---|---| | 0 | emerg | | 1 | alert | | 2 | crit | | 3 | err | | 4 | warning | | 5 | notice | | 6 | info | | 7 | debug |

Lower numbers are more urgent.

rsyslog rules

The main file is /etc/rsyslog.conf, with extra files in /etc/rsyslog.d/. A classic rule has a selector and an action:

mail.info        /var/log/mail.log
*.emerg          :omusrmsg:*
authpriv.*       /var/log/secure

mail.info means mail messages of severity info or more serious. * is a wildcard. :omusrmsg:* writes to all logged-in users. Default rules differ between distributions.

After editing, check the syntax and restart:

$ sudo rsyslogd -N1
$ sudo systemctl restart rsyslog

Sending a test message

logger puts a message into the system log:

$ logger -p local0.warning -t backup "disk nearly full"
$ journalctl -t backup -n 1
Jan 05 10:12:25 web01 backup[5120]: disk nearly full

-p sets facility and severity, and -t sets the tag. The process ID shown may vary.

Remote logging

rsyslog can forward messages to a central server. In a classic rule, a single @ means UDP and @@ means TCP:

*.*  @@logs.example.com:514

The receiving server must be configured to listen. Plain forwarding is not encrypted, so use TLS across untrusted networks.

Try it

Run logger "hello from me", then find it with journalctl -n 5. If your system has /var/log/syslog or /var/log/messages, search it with sudo grep "hello from me" too. Read man rsyslog.conf if rsyslog is installed.

Check your understanding

syslog

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.