System logging
System logging: the facility-and-severity scheme every syslog daemon uses, the configuration files that route messages to files, and the systemd journal that sits alongside or instead of them.
Lesson 2 of 4 in objective 108. Essential system services, part of LPIC-1 Exam 102-500.
Facilities and severities
A syslog message carries a FACILITY, saying what kind of thing produced it — auth and authpriv, cron, daemon, kern, mail, user — and a SEVERITY. The severities, most to least serious, are emerg, alert, crit, err, warning, notice, info, debug. A configuration line names a selector like mail.err and a destination, and it matches that severity AND EVERYTHING MORE SEVERE. mail.=err matches only that level, and mail.* matches all of them.
Eight of the facilities are reserved for whatever a site wants, and they are named individually rather than as a range: local0, local1, local2, local3, local4, local5, local6, local7. Nothing in the system claims them, which is the point — an in-house application logs to one of the eight and gets its own file without competing with daemon or user for a selector. A question that asks which facility to give a bespoke service is asking for one of these, and it will spell it out in full.
rsyslog is the usual daemon and reads /etc/rsyslog.conf plus /etc/rsyslog.d/; syslog-ng is the alternative with a rather different configuration syntax. Destinations are usually files under /var/log — /var/log/messages or /var/log/syslog for the general stream, /var/log/auth.log or /var/log/secure for authentication — and can also be a remote host, which is how central logging is built. logger sends a message into syslog from a script or the command line, which is also how you test that a rule works.
The journal, and log rotation
systemd-journald collects everything — kernel messages, service output on standard output and standard error, and syslog traffic — into a structured binary journal. journalctl reads it: -u NAME for one unit, -b for this boot, -f to follow, -p err to filter by priority, --since and --until for a time window. It is binary by design, which is why it cannot be read with less and why it can be queried by field. By default it may be volatile, kept in /run and lost on reboot; making it persistent means creating /var/log/journal.
Getting a script INTO the journal has its own command, and it is not logger. systemd-cat -t maintenance /usr/local/sbin/maintenance.sh runs the script with both its standard output and its standard error redirected into the journal, so progress and problems alike arrive tagged and come back out with journalctl -t maintenance. Given no command it forwards its own standard input instead, which is the piped form. -t sets the identifier and -p the default priority. logger is the neighbouring tool and writes ONE message through the syslog interface — it takes -t and -p too, which is what makes the pair easy to confuse — so logger is for a line and systemd-cat is for a whole program's two streams.
Text logs grow forever unless something stops them, and that something is logrotate: /etc/logrotate.conf plus per-package files in /etc/logrotate.d/ say how often to rotate a file, how many old copies to keep, whether to compress them, and what command to run afterwards so the daemon reopens its file. The journal handles its own size limits in journald.conf instead.
The default rotation is a RENAME followed by the creation of a fresh file, and it only works because the writing process is then told to reopen its log — which is what the postrotate script calling systemctl reload or kill -HUP is for. A daemon that holds its file open and offers no way of being signalled keeps writing into the renamed file, and the new one stays empty forever. copytruncate is the directive for that case: logrotate copies the file and then truncates the original in place, so the descriptor the daemon is holding stays valid. It carries a small race — anything written between the copy and the truncate is lost — which is why it is the exception rather than the default.
Worth carrying in
- facility.severity
- A selector such as
mail.err— that level and everything more severe. - emerg alert crit err warning notice info debug
- Severities, most to least serious.
- local0 … local7
- The eight facilities reserved for local use. Nothing in the system claims them.
- /etc/rsyslog.conf
- Routing rules, plus drop-ins in
/etc/rsyslog.d/. - logger -p auth.info "…"
- Send a message into syslog from a script.
- journalctl -u sshd -b
- One unit, this boot. -f follows, -p filters by priority.
- /var/log/journal
- Create it to make the journal persist across reboots.
- systemd-cat -t NAME cmd
- Run a command with both its streams going into the journal under that identifier.
- logrotate
- Rotates, compresses and expires text logs.
/etc/logrotate.d/per package. - copytruncate
- Copy then truncate in place, for a daemon that cannot be told to reopen its log.
What the exam does with this
- A selector matches the named severity and everything above it. The = prefix is what restricts it to one level.
- Know the severity ORDER — a question will ask which of two is more serious.
- The journal is binary and queried with
journalctl; it is not a text file you cangrepdirectly. - A bespoke application gets one of
local0throughlocal7. Any other facility means competing with something that already owns it.
- Objective
- 108. Essential system services
- Share of the exam
- 18.33% (the whole objective)
- Questions in this lesson
- 20
- Signed for by a person
- 0
Partly checked. None of the 20 questions here has been read against the cited source by a person. 20 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
Drill this lesson
A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.
Questions in this lesson
- An rsyslog rule reads `mail.warning /var/log/mail-problems`. Which messages from the mail facility does this rule write to that file? machine-checked
- Which of the following are valid standard syslog facility names usable on the left-hand side of an rsyslog selector? (Choose three.) machine-checked
- A backup shell script must write its own status line into the system log through the syslog service. Type the name of the standard command-line utility it should call (command name only, no options). machine-checked
- Which statement correctly describes how logrotate is configured on a typical distribution? machine-checked
- You want to watch new log entries for the sshd service as they arrive, on a systemd host. Which command does exactly that? machine-checked
- A server crashed and has since rebooted. You want the journal entries of severity error and above from the boot before the current one. Which command retrieves them? machine-checked
- On a host where journalctl shows nothing from before the last reboot, which change makes the journal persist across reboots? machine-checked
- On a distribution that runs both systemd-journald and rsyslog, which two statements are correct? (Choose two.) machine-checked
- A line in /etc/rsyslog.conf reads `*.info;mail.none;authpriv.none;cron.none /var/log/messages`. What does the `mail.none` component do? machine-checked
- In an rsyslog rule the action is written as `-/var/log/debug` rather than `/var/log/debug`. What is the effect of the leading hyphen? machine-checked
- An incident happened between 09:00 and 10:00 this morning and you want the journal entries from exactly that window, with nothing from before or after. Which command restricts the output that way? machine-checked
- /var/log/journal on a busy server has grown to several gigabytes. You want to reclaim space now by discarding archived journal data older than 30 days, without stopping journald. Which command does that? machine-checked
- A server no longer boots. You have started a rescue system from removable media and mounted the broken machine's root filesystem at /mnt. Which command reads that machine's persistent journal? machine-checked
- Persistent journalling is enabled and you must guarantee that the journal never occupies more than 200 MB under /var/log/journal. Which setting in /etc/systemd/journald.conf enforces that ceiling? machine-checked
- A nightly maintenance script prints progress on standard output and problems on standard error. Both streams should end up in the systemd journal under an identifier you can filter on later. Which invocation achieves that? machine-checked
- Type the journalctl invocation that shows only kernel messages — the journal's equivalent of dmesg (do not include a path). machine-checked
- An in-house daemon holds its log file open and offers no way of being told to reopen it. After each rotation it keeps writing into the renamed file, so the new log stays empty. Which logrotate directive resolves this? machine-checked
- Which THREE statements about logrotate directives and how logrotate is run are correct? (Choose three.) machine-checked
- Which TWO statements about syslog priorities and how rsyslog selectors match them are correct? (Choose two.) machine-checked
- Type the absolute path of the directory in which systemd-journald keeps the journal once persistent storage is in effect. machine-checked
The rest of objective 108
- Keeping system time correct
- System logging — you are here
- Mail transfer agent basics
- Printers and printing