SkillSprout
Chapter 2 · Lesson 8
Intermediate
1 min read

Logs and journalctl

Overview

Linux logs record service events, kernel messages and application output. systemd journal entries are queryable through journalctl. Traditional logs may exist as files under /var/log.

Detailed Notes

Service logs

bash
journalctl -u nginx
journalctl -u nginx -f
journalctl -u nginx --since "10 minutes ago"
journalctl -u nginx -p err
  • -u filters by unit.
  • -f follows new entries.
  • --since limits the time range.
  • -p err shows error priority and above.

System logs:

bash
journalctl -b
journalctl -k
journalctl --disk-usage
  • -b shows the current boot.
  • -k shows kernel messages.
  • --disk-usage shows journal storage.

File logs

bash
tail -n 100 /var/log/syslog
tail -f /var/log/app.log
grep -i error /var/log/app.log

Use tail -f only for active diagnosis. For a large file, filter a recent time range or count matching lines before reading the full log.

Correlate events

When an HTTP request fails:

  1. Find the service logs.
  2. Record the UTC or local timestamp.
  3. Inspect application logs for the request ID.
  4. Inspect kernel or reverse-proxy logs for connection or TLS failure.
  5. Correlate by time and request identity.

Do not delete logs to solve disk pressure until retention and backup policies are understood.

Common Interview Questions

Finished this lesson?

0 of 25 lessons done · 0% of the course