Skip to content
rhaen edited this page Sep 5, 2011 · 2 revisions

logrotate

Log production.log increase little by little after you application is deployed in production environment.

If you want to maintain production log on CentOS, Debian, Ubuntu and Fedora, it is easy to use logrotate.

You create logrotate config file in your application directory(in this example, webapp)

cd ~/webapp
mkdir logrotate
cd logrotate
vi logrotate.conf

The following setting is one example. Current log is copied to ohter file once per week. Logs before 12 weeks are deleted.

/home/ken/webapp/log/production.log {
  weekly
  copytruncate
  rotate 12
  missingok
}

Let's register the command which execute rotation to crontab.

crontab -e

You write the following setting.

0 0 * * * /usr/sbin/logrotate -s $HOME/webapp/logrotate/logrotate.status $HOME/webapp/logrotate/logrotate.conf
Clone this wiki locally