Skip to content
yuki-kimoto edited this page Sep 5, 2011 · 4 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, 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 is 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 folloing setting.

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