Logging
Cheat sheet · https://pcornel.dk/topic.php?topic=2819
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 bootjournalctl -u <unit> -f— follow one unit's logls -lh /var/log— log files and sizeslogger -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 50journalctl -b -1 -p errjournalctl --since "14:00" --until "14:10"journalctl -fu report-apijournalctl -k -bjournalctl _COMM=sshd _COMM=sudo --since todayjournalctl -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