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
-ufilters by unit.-ffollows new entries.--sincelimits the time range.-p errshows error priority and above.
System logs:
bash
journalctl -b
journalctl -k
journalctl --disk-usage
-bshows the current boot.-kshows kernel messages.--disk-usageshows 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:
- Find the service logs.
- Record the UTC or local timestamp.
- Inspect application logs for the request ID.
- Inspect kernel or reverse-proxy logs for connection or TLS failure.
- 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

