Introduction

One of the most embarrassing ways a high-traffic production server can crash is by running out of disk space due to runaway log files.

Every HTTP request, PHP warning, MySQL slow query, and authentication attempt writes to server logs.

If log files grow to 20GB without rotation, the disk fills up to 100%, MySQL freezes, and the entire website goes dark.

Here is how senior system administrators automate log rotation and parse logs to detect operational issues.

Linux logrotate server log management and parsing architecture
Linux logrotate server log management and parsing architecture

Configuring logrotate for Daily Compression

Linux includes the logrotate utility designed to manage log archives automatically.

Configure /etc/logrotate.d/nginx to rotate logs daily, compress old logs with gzip, and retain only 14 days of historical logs (rotate 14).

Enable delaycompress so the most recent rotated log file remains uncompressed until the next cycle for active debugging.

Old logs are automatically purged on day 15, keeping disk consumption predictable and low.

Real-Time Terminal Log Parsing with GoAccess

Searching through millions of lines of raw text logs with grep is tedious and slow.

GoAccess is a real-time visual web log analyzer that runs directly in your server terminal or outputs static HTML dashboards.

It instantly visualizes top HTTP 404 errors, highest bandwidth-consuming assets, top visitor IPs, and bot crawler patterns in seconds.

It is the fastest way to diagnose why server bandwidth or CPU suddenly spiked.

EXPLORE SPECIALIZED SERVICE

DevOps & Server Maintenance

RECOMMENDED SERVICEDevOps & Server MaintenanceTailored engineering, complete client ownership & clean code.
DIRECT INQUIRYDiscuss Your Project ScopeGet a transparent quote and delivery timeline within 24 hours.

Separating Access Logs from Error Logs

Always maintain separate log files for general access and error events.

Keep error_log at notice or warn level in production to keep error files focused on genuine PHP exceptions and fatal crashes.

For high-volume APIs, consider disabling static asset logging (images, fonts, CSS) from access logs to save millions of disk writes.

Clean log files make troubleshooting painless during an outage.

Frequently Asked Questions

How do I check current disk usage on my server?: Run df -h in your terminal to see disk capacity, and du -sh /var/log to see log directory sizes.

Can logs be shipped to an external service?: Yes, tools like Datadog, Papertrail, or Grafana Loki can stream logs off-server for centralized monitoring.

Are server IP logs subject to privacy laws like GDPR?: Yes, IP addresses are considered personal data; configure log retention policies to delete logs after 14 to 30 days.

CONTINUE READING

Related Insights & Guides