Log rotation, the unglamorous essential
Ask anyone who runs small servers how one died, and a surprising number of stories end with a disk at one hundred percent and a log file the size of a feature film. Logs grow forever unless something tells them not to. That something is usually logrotate, already installed, waiting to be told about your files.
The ninety-percent configuration
/var/log/myapp/*.log {
weekly
rotate 8
compress
missingok
notifempty
copytruncate
}
Weekly rotation, eight copies kept, compressed. missingok and notifempty keep quiet weeks quiet. copytruncate is the pragmatic choice for programs that hold their log file open and cannot be told to reopen it.
Test it before it matters
The command that makes this a routine instead of a hope: logrotate -d /etc/logrotate.d/myapp — a debug run that prints what would happen without doing it. Read the output once, fix the path you typo'd, and the job is done for the life of the service.
Rotation is not archiving. Eight weeks of logs answer "what changed recently"; they will not answer questions about last year. For the two services where old logs matter, a monthly copy goes to the backup drive — a different tool for a different job.