Linux Command Reference ยท Systemd and Logging (Read-Only)
syslog and rsyslog
Classic Linux logging explained: syslog facilities and priorities, rsyslog selector rules, log files under /var/log, remote forwarding and how it meets journald.
syslog is both a message format and a decades-old convention: programs send a line of text tagged with a facility (what kind of program it is) and a priority (how serious it is), and a daemon routes it to files, terminals or other machines. rsyslog is the most common modern daemon that does this. It receives messages from the journal or /dev/log and writes the familiar text files in /var/log, such as syslog, auth.log, messages and kern.log.
Plain text logs are easy to grep, rotate and ship to a central server, which is why they survive alongside the binary journal. Configuring rsyslog needs root, so this page is read-only; the examples parse sample syslog lines and a sample rules file.
logger -p auth.notice "user logged in" grep sshd /var/log/auth.log # /etc/rsyslog.conf or /etc/rsyslog.d/*.conf auth,authpriv.* /var/log/auth.log
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
A classic rule is SELECTOR ACTION. A selector is facility.priority; several are separated by ; and facilities by ,.
facility[,facility].priority[;facility.priority] ACTION auth,authpriv.* /var/log/auth.log # file *.err @@loghost.example.com:514 # TCP forward (@ = UDP) *.*;auth.none -/var/log/syslog # '-' = do not sync every write
| Name | Description |
|---|---|
| Facility | kern, user, mail, daemon, auth, authpriv, syslog, lpr, news, uucp, cron, local0 to local7. The last eight are for your own applications. |
| Priority | emerg, alert, crit, err, warning, notice, info, debug (see Log priorities). A selector matches that level and everything more severe. |
* |
Any facility or any priority. |
none |
Exclude a facility: *.*;mail.none. |
= and ! |
kern.=info is exactly info; kern.!err is everything except err and above. |
| Action file | Path to append to. /dev/null discards; :omusrmsg:user writes to a user's terminal. |
| Action forward | @host (UDP) or @@host (TCP) sends to a remote syslog server. |
Returns: logger exits 0 when it handed the message to syslog. rsyslogd -N1 validates the configuration and prints errors.
Errors and edge cases: rsyslog ignores unreadable include files silently in some versions; test with rsyslogd -N1 and read systemctl status rsyslog after a change.
Usage notes
- Where files are depends on the distribution. Debian and Ubuntu use
/var/log/syslogandauth.log; RHEL, Fedora and CentOS use/var/log/messagesandsecure. - Many distributions now use only the journal and install rsyslog on request. Both can coexist: journald forwards each message to rsyslog.
- Rotate the files. Text logs grow without limit;
logrotaterenames and compresses them (seelogrotate). - Write your own messages with
logger -t mytool -p local3.info "text"and route them with alocal3.*rule. - UDP can drop messages. Use TCP (
@@) or RELP for important central logging, and consider TLS across networks. - Timestamps in the traditional format have no year and no time zone; newer rsyslog templates can write ISO 8601 (
RSYSLOG_FileFormat). - Permissions.
auth.logis readable only byrootand theadmgroup because it contains usernames and addresses. - Order matters little but
stopmatters: a rule ending with& stop(orstopin RainerScript) prevents later rules from seeing the message.