๐ Day 14: Effective Log Management and Rotation Strategies


Welcome to Day 14 of my 100 Days of DevOps journey!
Today I explored log management and log rotation โ an essential DevOps skill for system stability, debugging, auditing, and monitoring.
๐ What Are Logs in Linux?
Logs are system-generated messages that record everything from boot information, user actions, process statuses, and service errors.
๐๏ธ Common Linux log files:
Log File | Purpose |
/var/log/syslog | General system activity logs |
/var/log/auth.log | Authentication (login, sudo) logs |
/var/log/kern.log | Kernel-related messages |
/var/log/dmesg | Boot & hardware events |
/var/log/cron.log | Scheduled job logs (if enabled) |
๐ View logs using:
sudo tail -f /var/log/syslog
sudo journalctl -u ssh.service
grep "error" /var/log/auth.log
๐ Why Log Rotation Matters
Without rotation, log files can grow indefinitely and consume disk space.
Log rotation helps by:
Archiving old logs
Compressing them to save space
Automatically deleting older ones
Keeping systems clean and readable
๐ง Tool: logrotate
Most Linux systems use logrotate
to automate log rotation.
๐ Default config:
Global:
/etc/logrotate.conf
Per-app:
/etc/logrotate.d/
๐ My Custom Log Rotation Setup
โ 1. Simulate a Log File
mkdir -p ~/logs
echo "Log started at $(date)" > ~/logs/myapp.log
Then simulate appending:
nohup bash -c 'while true; do echo "$(date): app log entry" >> ~/logs/myapp.log; sleep 2; done' &
๐ 2. Create Logrotate Config
Create a file:
sudo nano /etc/logrotate.d/myapp
Paste:
Paste:
/home/ritesh/logs/myapp.log {
daily
rotate 5
compress
missingok
notifempty
create 644 ritesh ritesh
su ritesh ritesh
}
๐ Explanation:
daily
: rotate once per dayrotate 5
: keep 5 old logscompress
: gzip old logscreate
: re-create log after rotationsu
: run rotation as my user
๐งช 3. Test It
๐ Dry run:
sudo logrotate -d /etc/logrotate.d/myapp
๐ Force rotation:
sudo logrotate -f /etc/logrotate.d/myapp
๐ Result:
ls -lh ~/logs/
# myapp.log -> current log file
# myapp.log.1.gz -> rotated & compressed
๐ง Extras
๐งน Clean old systemd journal logs:
sudo journalctl --vacuum-time=2weeks
๐งฐ Useful tools:
๐ Key Learnings
โ
Understood core Linux logs and their importance
โ
Learned how to manage logs using logrotate
โ
Created a real-time rotating app log
โ
Prepared for production-grade log hygiene
๐ References:
๐ Hashnode Blog: Day 14 โ Log Management and Rotation
๐ GitHub Repo: DevOps Journal
Subscribe to my newsletter
Read articles from Ritesh Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ritesh Singh
Ritesh Singh
Hi, Iโm Ritesh ๐ Iโm on a mission to become a DevOps Engineer โ and Iโm learning in public every single day.With a full-time commitment of 8โ10 hours daily, Iโm building skills in: โ Linuxโ Git & GitHubโ Docker & Kubernetesโ AWS EC2, S3โ Jenkins, GitHub Actionsโ Terraform, Prometheus, Grafana I post daily blogs on Hashnode, push projects to GitHub, and stay active on LinkedIn and Twitter/X. Letโs connect, collaborate, and grow together ๐ #100DaysOfDevOps #LearningInPublic #DevOps