Sub topic 2
Facilities and Severities
Assume you can use the Linux command line, understand basic systemd commands, and have seen files under /var/log. This chapter explains how syslog labels messages so that you can route, store, or ignore them.
Facilities identify the source
A syslog message has a facility, which identifies the part of the system that produced it. Facilities are labels, not physical files. For example, auth represents authentication messages, while kern represents messages from the kernel.
Common facilities include:
| Facility | Typical source |
|---|---|
| `kern` | Linux kernel |
| `user` | User-level applications |
| `mail` | Mail systems |
| `daemon` | Background services |
| `auth` or `authpriv` | Authentication and authorization |
| `cron` | Scheduled jobs |
| `local0` through `local7` | Locally assigned applications |
Applications can choose a facility when they write a message. The logger command lets you test this behavior:
logger --tag backup --facility local5 --priority warning "Backup finished with warnings"This sends a message with the tag backup, the local5 facility, and the warning severity.
Severities describe urgency
A severity describes how serious a message is. Syslog defines eight levels, from emerg, the most serious, to debug, the least serious.
| Name | Number | Meaning |
|---|---|---|
| `emerg` | 0 | System is unusable |
| `alert` | 1 | Immediate action is required |
| `crit` | 2 | Critical failure |
| `err` | 3 | Error condition |
| `warning` | 4 | Warning condition |
| `notice` | 5 | Normal but important event |
| `info` | 6 | Informational message |
| `debug` | 7 | Detailed diagnostic information |
Severity is a hint about urgency. An info message can still be valuable during an investigation, and an err message does not always mean that a service has stopped.
The complete syslog priority combines the facility and severity into a numeric value. You normally do not calculate it yourself. Tools and logging services handle that encoding.
Filtering with selectors
An rsyslog selector combines a facility with a severity threshold. In this example, messages from local5 at warning or higher are written to a separate file:
# /etc/rsyslog.d/30-backup.conf
local5.warning /var/log/backup.logThe warning threshold includes warning, err, crit, alert, and emerg. It does not include notice, info, or debug.
Use none to exclude a facility, and use a semicolon to provide multiple rules:
authpriv.* /var/log/secure.log
local5.warning /var/log/backup.log
*.info;mail.none /var/log/all-info.logHere, * means every facility or every severity, depending on its position. The last rule records informational and more serious messages from most facilities, but excludes the mail facility.
How the labels move through the system
These labels are useful because they separate message meaning from storage location. The same facility can be sent to a local file, forwarded to a central server, or both.
Exercise
Which messages match the rsyslog rule authpriv.err /var/log/auth-errors.log?
Show answer
Messages from the authpriv facility with severity err, crit, alert, or emerg match. Informational and warning messages do not.