Log rotation and maintenance in Ubuntu
Log files are useful when you want to know what is going on in your system. Logrotate is a perfect tool to manage your log files. If it is not already installed, you can install it by:
sudo apt-get install logrotate
Then you can edit the config file and add the log file that you want it to manage.
sudo pico /etc/logrotate.conf
A sample configuration to rotate your Rails production log:
/home/ubuntu/app_name/log/production.log {
daily
missingok
rotate 15
delaycompress
notifempty
copytruncate
}
You can define the filenames by wildcard such as:
/log/*_production.log {
}
Common configuration includes:
- rotate - How many files you want to keep?
- daily/weekly/monthly/yearly - How often a file rotate?
- compress/nocompress/delaycompress - Whether or not the old log is compressed?
- size - if you want to rotate by size
- copytruncate - when a rotate happens, clear the content of original log file by moving it to another file
- notifempty - Do not rotate the log if it is empty.
- missingok - Doesn't matter if the log file is missing.
Full list can be found here.
Chrome On-device AI
2025-03-21 14:44:38