Why Logging Matters
Logs are the heartbeat of a Linux system. Every service, application, and kernel component records events that help administrators understand what’s happening behind the scenes.
Linux logs help you to:
-
π Diagnose system and application issues
-
π‘οΈ Audit user activity and security events
-
π Monitor system performance and stability
-
π§ Troubleshoot boot, hardware, and service failures
Mastering logs is a core skill for Linux administrators, DevOps engineers, and SREs.
π Key Log Locations in Linux
| Path | Purpose |
|---|---|
/var/log/syslog |
General system messages (Debian/Ubuntu) |
/var/log/messages |
General system messages (RHEL/CentOS) |
/var/log/auth.log |
Authentication and sudo events |
/var/log/dmesg |
Kernel ring buffer messages |
/var/log/boot.log |
System boot process logs |
π Note: Log files vary slightly by Linux distribution, but
/var/logis the standard log directory.
π§Ύ Inspecting Logs with journalctl
Modern Linux systems use systemd, which stores logs in a structured binary format accessed using journalctl.
π§ Common Commands
-
Shows recent logs with detailed context and errors
-
Filters logs by time
-
Displays logs for a specific service
journalctl is powerful for tracing service failures and debugging production issues.
π§ Kernel Logs with dmesg
The dmesg command displays kernel and hardware-related messages, especially during boot.
-
View kernel logs interactively
-
Shows human-readable timestamps
Use dmesg when troubleshooting:
-
Disk and filesystem errors
-
Network and driver issues
-
Hardware detection problems
π Managing Logs with logrotate
Without log rotation, log files can grow endlessly and consume disk space. logrotate automates log maintenance.
π Configuration Location
-
/etc/logrotate.conf -
/etc/logrotate.d/
π Example Log Rotation Rule
This configuration:
-
Rotates logs weekly
-
Keeps 4 old copies
-
Compresses old logs
-
Avoids errors if logs are missing
π§ Pro Tips for Log Monitoring
-
π‘ Live log monitoring:
-
π Search logs for errors:
-
π§ͺ Debug logrotate rules:
These commands are invaluable during outages and incident response.
FAQs (0)
Sign in to ask a question. You can read FAQs without logging in.