388. Logs
When something on a KDOS machine fails, the reason is usually written down in a log. This page is for anyone tracking down such a failure: it lists where each kind of message goes, how to read and follow it, how to change where messages go, and which file to read for a given failure. Every command on this page runs on a running KDOS machine.
KDOS’s system log is written by syslogd, from sysklogd, into files under /var/log. Beside it, a few files under /run keep what the system log cannot: what each service script (one of the /etc/init.d scripts that start the system’s services) printed at boot, each supervised daemon’s recent output, and the boot-time filesystem check.
Installation
- sysklogd installs
syslogdand its configuration,/etc/syslog.conf. It is built without its ownlogger. /etc/init.d/22_syslog.sh, from the base filesystem, startssyslogdunder the supervisor as the servicesyslog. It runs before the network comes up./etc/init.d/20_dmesg.shsets the kernel’s console log level.ksvc, from kdos-tools, copies every supervised daemon’s output into the system log and into a file of its own under/run.- util-linux installs
logger, which writes a message into the system log, anddmesg, which reads the kernel’s ring buffer. It also installslast, which reads the login records; utmps keeps those.
The services syslog and dmesg are enabled on every image. On the live medium /var/log is in the overlay’s upper layer, which is memory unless a persistence store exists (kdos persist), so the log of a live session is gone at power-off. The installer copies no file under /var/log to the disk, so an installed system’s log and its last record begin at its first boot. On an installed system the log is on the root filesystem and survives a reboot. /run is a tmpfs on both, so everything under it is gone at every reboot.
Configuration
/etc/syslog.conf
The sysklogd port’s build.sh writes the file:
cat > "$PKG/etc/syslog.conf" <<'EOF'
# facility.level destination
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/messages
kern.* -/var/log/kern.log
cron.* -/var/log/cron
*.=emerg *
# Rotation is GLOBAL directives, not per-file suffixes. Writing
# `/var/log/messages rotate_size=1M` puts the path where a facility.priority
# selector belongs and syslogd answers `unknown priority name ""` for every
# such line.
rotate_size 1M
rotate_count 5
# No network socket at all. With no `listen` line syslogd otherwise opens UDP
# *:514 and accepts any host's messages into these files. 1 would keep
# forwarding to a remote `@host` action without listening; 2 is neither.
secure_mode 2
EOF
ports/core/base/sysklogd/build.sh, lines 26–45
Each rule is a selector, facility.level, and a destination; a - before a path writes without syncing after every message. The routing, the rotation and secure_mode are described in Logs. syslog.conf(5), installed by the port, is the reference for every directive, include among them.
/etc/init.d/22_syslog.sh
. /etc/init.d/service_helper
NAME="syslogd"
DAEMON="/usr/sbin/syslogd"
case "$1" in
start)
if [ ! -x "$DAEMON" ]; then
echo "[SKIP] $NAME: $DAEMON not found"
exit 0
fi
echo "[KDOS] Starting $NAME..."
mkdir -p /var/log
# Runs before the network (30_network) on purpose: a boot that fails
# while bringing an interface up is exactly the one whose log you want.
# -F keeps it in the foreground for ksvc; without it the supervisor
# watches a process that has already forked away.
# -P keeps syslogd's own pid file in /run/syslogd/ beside its cache;
# the supervisor's is /run/kdos-svc.syslogd.pid and is what `stop`
# and `status` read.
# -8 writes bytes 0x80-0x9F as they arrive. Without it syslogd
# rewrites each as `M-^x`, and those bytes are the continuation bytes
# of most UTF-8 punctuation, so one em dash leaves a lone lead byte
# in the file and grep calls /var/log/messages binary. ASCII control
# characters are still escaped as `^x`.
# syslogd creates a missing log file 0644 and keeps the mode of an
# existing one across rotation, so these three are made root-only
# here. Left to syslogd, every account could read who ran sudo and
# which logins failed (auth.log), and the kernel's lines that dmesg
# refuses it (kern.log, and messages, which takes kern.* too).
for _log in /var/log/auth.log /var/log/kern.log /var/log/messages; do
[ -e "$_log" ] || : > "$_log"
chmod 600 "$_log"
done
# -l on a boot without `quiet`: syslogd otherwise turns the kernel's
# console logging off when it opens the kernel log, and a verbose
# boot would go silent on the screen here. 20_dmesg.sh is the other
# half of that rule.
# -T stamps every line with syslogd's own local time: musl's
# syslog() writes its timestamp in UTC, so on any other time zone
# a program's lines would sit an offset away from the kernel's.
_keep=()
grep -qw quiet /proc/cmdline 2>/dev/null || _keep=(-l)
mkdir -p /run/syslogd
supervise "$NAME" "$DAEMON" -F -8 -T "${_keep[@]}" -P /run/syslogd/syslogd.pid
;;
stop)
stop_service "$NAME"
;;
status)
check_status "$NAME"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
/etc/init.d/20_dmesg.sh
. /etc/init.d/service_helper
NAME="dmesg"
case "$1" in
start)
# A boot without `quiet` (the verbose and single-user entries) is
# one asked to show its messages: the console level stays the one
# its `loglevel=` set. 22_syslog.sh keeps it there too.
if ! grep -qw quiet /proc/cmdline 2>/dev/null; then
echo "[KDOS] Verbose boot: console log level left as set"
exit 0
fi
echo "[KDOS] Suppressing kernel messages on console..."
dmesg -n 3
;;
stop)
# Restore default log level
dmesg -n 7
;;
status)
echo "[ OK ] $NAME: console log level configured"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
What the console shows depends on whether the command line carries quiet:
- With
quiet(every entry that boots to the desktop),20_dmesg.shsets level 3, so the console shows only the kernel’s messages more urgent than an error: critical, alert and emergency.22_syslog.shthen startssyslogd, which lowers it further: when it opens the kernel’s log it turns the kernel’s console logging off, which leaves the level at 1, emergencies only, for as long as it runs.cat /proc/sys/kernel/printkstarts1. - Without
quiet(the verbose and single-user entries),20_dmesg.shleaves the level theloglevel=word set, and22_syslog.shstartssyslogd -l, which keeps the kernel’s console logging on.cat /proc/sys/kernel/printkstarts7.
Either way every message still reaches the ring buffer and the system log.
Where each kind of message goes
| Message | File | Kept |
|---|---|---|
| Everything but authentication | /var/log/messages (root only, mode 0600, set by 22_syslog.sh before syslogd starts) |
Rotated by size, as rotate_size and rotate_count say; older copies gzipped |
Logins, sudo, polkit, other authentication |
/var/log/auth.log (root only, mode 0600, set by 22_syslog.sh before syslogd starts) |
The same |
| The kernel | /var/log/kern.log (root only, mode 0600, the same way), and dmesg |
The same; the ring buffer until it wraps |
The cron facility |
/var/log/cron; nothing on the image logs there |
The same |
| A service script’s output at boot | /run/kdos-init.<service>.log |
Until reboot |
| A supervised daemon’s output | /run/kdos-svc.<name>.log (root only, mode 0640), and the system log tagged <name> |
64 KiB, one .old beside it |
| The boot-time check of non-root filesystems | /run/kdos-fsck.log, when it reported anything |
Until reboot |
A console’s kdos-getty |
/run/kdos-getty.<tty>.log |
Until reboot |
| SDDM and the greeter | /var/log/sddm.log |
The first start of each boot moves the last boot’s to sddm.log.old |
| The Plasma session: KWin, plasmashell and everything the session starts | ~/.local/share/sddm/wayland-session.log |
Each login replaces it |
| A user’s own services: the session bus, PipeWire, the user timers | $XDG_RUNTIME_DIR/ksvc/kdos-svc.<name>.log, and the system log |
Until the user’s last logout |
| The installer | /var/log/kinstall.log on the system it ran from, root only; the copy to the installed system leaves it out |
Appended to by every run |
| Logins, logouts, boots | /var/log/wtmp, read by last |
Appended |
<service> is the script’s name without its number and .sh, such as chrony; <name> is the name the script gave the supervisor, such as chronyd. The two differ for some services; see Services. The /run files are listed in /run/ — system runtime.
A supervised daemon that wrote to the system log itself and copied each line to its standard error would reach the log twice, so each is set to one of the two. ModemManager writes to standard output and is logged under ModemManager; dbus-daemon runs with --syslog-only, its lines carry the tag dbus-daemon, and /run/kdos-svc.dbus.log holds only what the services the bus starts print.
Usage
Reading the system log
Page through it, or follow it as messages arrive:
sudo less /var/log/messages sudo tail -f /var/log/messagesPick out one daemon. Each supervised daemon’s lines carry its name as the tag:
sudo grep 'kdos-powerd' /var/log/messagesA line carries the time, the host name, the tag and the message:
Oct 21 19:10:29 kdos kdos-powerd: [KDOS] (kdos-powerd) Starting: /usr/sbin/kdos-powerd.syslogdruns with-8, so a message in UTF-8, such askdos-oomd’s kill line with its—, is written as it was sent and the file stays text. ASCII control characters in a message are still written as^x. It runs with-Ttoo, so the time is the machine’s local time when the line was logged, not the sender’s own stamp, which musl’ssyslog()writes in UTC.Authentication is kept apart, in a file of its own:
sudo tail -n 50 /var/log/auth.logThe older copies sit beside each file:
messages.0is the most recent, and the ones before it are compressed,messages.1.gzonwards:ls -l /var/log sudo zcat /var/log/messages.1.gz | less
Reading what a boot printed
Find the service scripts’ logs from this boot:
ls /run/kdos-init.*.logRead one:
cat /run/kdos-init.networkmanager.logRead a supervised daemon’s own output, which stays readable before
syslogdstarts and while it restarts:sudo cat /run/kdos-svc.NetworkManager.log
Reading the kernel’s messages
sudo dmesg
sudo dmesg --level=err,warn
The ring buffer holds messages from before syslogd started. Reading it takes root, because the kernel is built with CONFIG_, which sets kernel.dmesg_restrict to 1; /etc/sysctl.conf leaves it there. The kernel’s messages are also in /var/log/kern.log and /var/log/messages, which are root only for the same reason.
Writing a message
From a script or a shell, with a tag of your choosing:
logger -t backup "finished, 4 GB written"
The line lands in /var/log/messages with the tag backup.
Reading the login records
last
who -b
who -r
last reads /var/log/wtmp, which the wtmpd service appends to, and who -b and who -r, the last boot and the current runlevel, ask utmpd; see Login records.
Changing where messages go
Edit
/etc/syslog.confas root. To keep a daemon’s messages in a file of their own as well, add a program filter, a!line naming the tag, at the end of the file, followed by the rules for that program:!kdos-powerd *.* -/var/log/powerd.logThe filter applies to the rules after it, so the lines above it still send the same messages to
/var/log/messages.syslog.conf(5)describes program, host and property filters.Restart the logger:
sudo service restart syslogCheck the result with
loggeras above.
Tips
kpkg check sysklogdreports an edited/etc/syslog.confas aconfigline, which does not count as a fault; see Checking an installed root.syslogdrotates its files itself, by therotate_sizeandrotate_countlines. There is nologrotatejob to configure.syslogdlistens on no network socket (secure_mode 2). To forward to another host, setsecure_mode 1and add an@hostdestination; it still accepts nothing from the network.- The periodic jobs do not log to the
cronfacility, so their output is not in/var/log/cron: it is under the tagkdos-timer-NAME. See Timers.
Troubleshooting
A service failed at boot. Read /run/kdos-init.<service>.log first, then /run/kdos-svc.<name>.log for a supervised daemon. When a boot stops maps every boot stage to the file that explains it.
/var/log/messages is missing or stops growing. syslogd is not running:
service status syslog
sudo cat /run/kdos-svc.syslogd.log
Start it with sudo service start syslog. Messages sent while it was down are not in the log, but each supervised daemon’s /run/kdos-svc.<name>.log still holds its recent output.
The console shows kernel messages over the login prompt. The console level was raised. Lower it again to the level a running syslogd keeps:
sudo dmesg -n 1
The splash shows fsck: errors left uncorrected, see /run/kdos-fsck.log. A filesystem in /etc/fstab, other than the root, has errors the automatic check did not repair, and it was mounted anyway. Read the file, then check the filesystem unmounted; see Checking a filesystem by hand.
The desktop crashed or never appeared. Log in on tty2 and read the session’s log, which lives in the desktop user’s home, and SDDM’s:
tail -n 40 ~/.local/share/sddm/wayland-session.log
sudo tail -n 40 /var/log/sddm.log
Known gaps
Known gaps lists nothing for this topic.
See also
- Logs: the routing and the rotation
- Supervision and logging: how a daemon’s output reaches syslog and
/run - When a boot stops: which file to read for each boot stage
- /run/ — system runtime: every runtime file
- Services, Timers, Init and runlevels, The initramfs and the rescue shell