Logs are essential for diagnosing failed deployments, authentication problems, PHP exceptions, and resource exhaustion. A useful logging strategy makes events searchable while preventing logs from filling the filesystem or exposing secrets. Linux systems commonly use systemd-journald, while application and web-server logs may also be managed with ordinary files and logrotate.
Search the system journal
Examples:
journalctl -u nginx --since "1 hour ago"
journalctl -u php-fpm --since today
journalctl -p warning..alert
journalctl -f
Service names vary by distribution. Use systemctl list-units to identify the actual unit. Filter by time and service before exporting large volumes of logs. Journal retention can be persistent or volatile depending on system configuration.
Rotate file-based logs
A logrotate rule defines rotation frequency, retention, compression, and whether a service must be signaled after a file is reopened. A generic example:
/var/log/example/*.log {
daily
rotate 14
compress
missingok
notifempty
create 0640 root adm
}
Do not copy ownership or post-rotate commands without checking which user writes the logs. Test a proposed rule with logrotate -d before forcing rotation. Some applications keep an open file descriptor after rotation and need a documented reload or reopen signal.
Protect sensitive information
Avoid logging passwords, session cookies, API tokens, payment data, or unnecessary personal information. Restrict log permissions and centralize logs over encrypted channels when remote collection is required. Define retention according to operational and legal needs rather than keeping everything forever.
Monitor disk use and investigate gaps
Check filesystem usage and the largest log directories:
df -h
du -sh /var/log/* 2>/dev/null
A sudden absence of logs can indicate a stopped service, a permissions problem, or a changed logging destination—not necessarily that the system is healthy. Alert on disk pressure and repeated service errors. Document where each application, PHP-FPM pool, Apache/Nginx instance, and database writes its logs.