🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

Linux Log Management and Analysis: Complete Guide (2026)

Linux Log Management and Analysis: Complete Guide (2026)

Quick Summary: Linux logs are your primary diagnostic tool for troubleshooting system issues, security incidents, and performance problems. Modern Linux uses journald (systemd journal) for structured logging alongside traditional syslog. This guide covers log locations, journalctl queries, log rotation, centralized logging, and practical analysis techniques.

Linux log management and analysis

Where Linux Stores Logs

Log FileContentsKey Use
/var/log/syslogGeneral system messagesFirst place to check for issues
/var/log/auth.logAuthentication eventsSSH logins, sudo usage, failed attempts
/var/log/kern.logKernel messagesHardware issues, driver errors
/var/log/nginx/Web server logsAccess patterns, errors
/var/log/postgresql/Database logsSlow queries, errors
/var/log/fail2ban.logIntrusion preventionBanned IPs, attack patterns
/var/log/cronCron job executionScheduled task success/failure

journalctl: Modern Log Queries

CommandPurpose
journalctl -u nginxLogs for a specific service
journalctl -u nginx --since "1 hour ago"Time-filtered logs
journalctl -u nginx -fFollow logs in real time
journalctl -p errOnly error-level messages
journalctl -bLogs since last boot
journalctl -b -1Logs from previous boot
journalctl --since "2026-03-25" --until "2026-03-26"Date range query
journalctl -o json-prettyJSON output for parsing
journalctl --disk-usageCheck journal storage size

Log Rotation with logrotate

logrotate prevents log files from consuming all disk space:

  • Configuration: /etc/logrotate.conf and /etc/logrotate.d/
  • Key directives: daily/weekly/monthly, rotate 14 (keep 14 rotations), compress, missingok, notifempty
  • Test: logrotate -d /etc/logrotate.conf (debug/dry-run mode)
  • Force rotation: logrotate -f /etc/logrotate.conf

Practical Log Analysis Techniques

  • Find failed SSH logins: grep "Failed password" /var/log/auth.log | tail -20
  • Count requests per IP: awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10
  • Find 500 errors: grep " 500 " /var/log/nginx/access.log
  • Monitor disk space alerts in syslog: grep -i "no space" /var/log/syslog
  • Check OOM killer activity: grep -i "out of memory" /var/log/kern.log

Centralized Logging

ToolTypeBest For
ELK Stack (Elasticsearch, Logstash, Kibana)Full-featuredLarge deployments, search and analytics
Loki + GrafanaLightweightKubernetes, cost-effective
GraylogEnterpriseCompliance, alerting
rsyslog forwardingSimpleSmall setups, central syslog server

Frequently Asked Questions

How long should I keep logs?

Security logs: minimum 90 days (many regulations require 1 year). Application logs: 30-90 days depending on debugging needs. Access logs: 30 days minimum for traffic analysis. Always balance retention with storage costs.

How do I find why my server crashed?

Check journalctl -b -1 for logs from the previous boot. Look for OOM killer messages (grep "oom" /var/log/kern.log), kernel panics, or service failures. Check dmesg for hardware-related issues.

What is the difference between syslog and journald?

journald is systemd's structured logging system with powerful querying. syslog (rsyslog) is the traditional text-based logging system. Most modern distributions run both: journald captures all logs, rsyslog writes traditional log files. They complement each other.

Related Resources

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.