Pcornel
Linux

Logging

Cheat sheet · https://pcornel.dk/topic.php?topic=2819

Back to the Topic

Answer

Linux logging has two main paths: systemd-journald collects kernel, service and syslog messages in a binary journal, and rsyslog (or syslog-ng) writes text files under /var/log and can forward messages to a central server.

Remember

Start with journalctl for services and the kernel; use /var/log files for applications that write their own logs. Make the journal persistent (/var/log/journal) to keep logs across reboots. Forward to a central server for security and correlation.

First checks

  • journalctl -b -p warning — warnings and errors since boot
  • journalctl -u <unit> -f — follow one unit's log
  • ls -lh /var/log — log files and sizes
  • logger -p user.info test — send a test message

Commands

journalctl
Query systemd journal records by unit, boot, time, priority or structured field.
journalctl -u nginx -b -n 50
journalctl -b -1 -p err
journalctl --since "14:00" --until "14:10"
journalctl -fu report-api
journalctl -k -b
journalctl _COMM=sshd _COMM=sudo --since today
journalctl -b -g "connection refused"
journalctl -b -p err

Verify in this order

event → written to the journal (and/or syslog) → stored locally → rotated → forwarded centrally

Where it usually breaks

First mismatch in persistent unit/config/generator → dependency/order graph → systemd state → process/cgroup → socket/resource dependency → journal → consumer check; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2819

Confirmation

Confirm action

Continue?