Sub topic 2
Facilities and Severities
This chapter assumes you can read basic rsyslog or syslog configuration, use journalctl, and run commands with sudo. It covers the two labels that every syslog message carries, how they are encoded, and how rules and tools use them to route and filter messages.
The two labels on every message
Every syslog message carries a facility and a severity.
- The facility says which kind of source produced the message, such as the kernel, the mail system, or a cron job.
- The severity says how urgent the message is.
Routing rules in rsyslog match on this pair. A rule can send all authentication messages to one file and forward everything at err or worse to a central host.
The labels are conventions. Nothing stops a program from logging with the wrong facility, so treat them as routing hints.
Facilities
The facility is a number from 0 to 23. The names below are the ones rsyslog accepts in rules.
| Number | Name | Typical source |
|---|---|---|
| 0 | kern | Kernel messages only |
| 1 | user | Generic user-level programs |
| 2 | Mail servers | |
| 3 | daemon | System daemons without their own facility |
| 4 | auth | Login and security messages |
| 5 | syslog | Messages generated by the syslog daemon itself |
| 9 | cron | cron and similar schedulers |
| 10 | authpriv | Private authentication messages, such as sudo and sshd |
| 16 to 23 | local0 to local7 | Reserved for site-specific use |
The numbers 6, 7, 8, 11 and others also exist (lpr, news, uucp, ftp), but you will rarely need them.
Two points cause regular confusion:
authandauthprivare separate. Many distributions sendauthprivto a restricted file such as/var/log/auth.logor/var/log/secure, because it can contain sensitive details. If your rule matches onlyauth, you can miss sshd and sudo events.- The
local0tolocal7facilities are yours to assign. A common practice is onelocalNper application or tier, so that rules can pick out that application's messages.
Severities
The severity is a number from 0 to 7. A lower number means a more urgent message.
| Number | Name | Meaning |
|---|---|---|
| 0 | emerg | System is unusable |
| 1 | alert | Act immediately |
| 2 | crit | Critical condition |
| 3 | err | Error |
| 4 | warning | Warning |
| 5 | notice | Normal but significant |
| 6 | info | Informational |
| 7 | debug | Debugging detail |
Because the scale runs from urgent to verbose, "at least this severe" means "this number or lower". This is the most common source of mistakes with severities.
How the two combine: the PRI value
On the wire, the facility and severity are packed into one number called PRI. It appears at the start of the message in angle brackets.
PRI = facility * 8 + severityTwo worked examples:
auth.warningis 4 * 8 + 4 = 36, sent as<36>.local0.erris 16 * 8 + 3 = 131, sent as<131>.
A receiver reverses this. It divides PRI by 8 to get the facility and takes the remainder as the severity. This is why the facility and severity survive forwarding between servers unchanged.
Selectors in rsyslog
A selector has the form facility.priority, followed by an action. The older selector syntax still works inside rsyslog's current configuration format.
# Everything from auth and authpriv, any severity
auth,authpriv.* /var/log/auth.log
# Everything except auth and authpriv
*.*;auth,authpriv.none /var/log/syslog
# Only err, not worse levels
mail.=err /var/log/mail.err
# local0 messages at warning or worse
local0.warning /var/log/myapp.logThe selector rules:
.warningmatches warning and everything more severe (warning, err, crit, alert, emerg)..=warningmatches that one level only..!warningmatches everything less severe than warning, which is the reverse of the plain form..noneexcludes a facility. It is how you stop a message from landing in two files.*is a wildcard for any facility or any severity.- Commas join facilities that share a priority, and semicolons join separate selectors. Later selectors in a semicolon list can modify earlier ones.
When you need more control, use a property-based filter. This rule matches the facility by name and the severity by number:
if $syslogfacility-text == "local0" and $syslogseverity <= 4 then {
action(type="omfile" file="/var/log/myapp-warn.log")
}Here $syslogseverity <= 4 is the numeric form of "warning or worse". It is also easy to read when the logic gets complicated.
A message can match several rules, and each matching rule runs. Unless a rule ends with stop, a message that matches *.* and local0.* is written to both destinations.
Labels in the journal and on the command line
journald stores the same two labels as the fields SYSLOG_FACILITY and PRIORITY. This preserves them when journald hands messages to rsyslog. You can filter on them directly:
# Errors and worse in the current boot
journalctl -p err -b
# A range of severities
journalctl -p warning..err
# Only messages logged with the local0 facility
journalctl --facility=local0Passing -p err includes crit, alert and emerg as well, which matches the selector behavior above.
To generate a message with a chosen label, use logger:
logger -p local0.err -t myapp "payment queue stalled"The -p option takes facility.severity, and -t sets the tag that rsyslog sees as programname. If you omit -p, logger uses user.notice.
Common mistakes
- Assuming a higher number is more severe. The scale runs the other way:
debugis 7 andemergis 0. - Writing
*.errand expecting only errors. It includescrit,alertandemergtoo. Use*.=errfor an exact match. - Forgetting
authpriv, then finding that sudo and ssh events are missing from a rule that matchedauth. - Letting a catch-all
*.*rule duplicate messages that a more specific rule already files elsewhere. Add;facility.noneto the catch-all to stop this. - Using
kernfor an application. Only the kernel should use it, so uselocalN.
Exercise
A client logs with logger -p local3.crit "disk failing". What PRI value goes on the wire, and which of these selectors match it: local3.err, local3.=err, *.warning, local4.*?
Show answer
PRI is 19 8 + 2 = 154, because local3 is facility 19 and crit is severity 2. local3.err matches, because crit is more severe than err. `.warning matches for the same reason. local3.=err does not match, because = requires exactly err. local4.*` does not match, because it is a different facility.
Exercise
Write a legacy-syntax rsyslog rule set that writes all messages to /var/log/all.log except authpriv messages, and writes authpriv messages of any severity to /var/log/secure.
Show answer
Use two rules:
.;authpriv.none /var/log/all.log
authpriv.* /var/log/secure
The authpriv.none term removes that facility from the first rule, so sensitive messages appear only in the restricted file.