unix

How do I rotate and compress my application logs?

The logrotate command is used in Linux to roll log files.  To rotate a new log file, perform the following steps:

cd /etc/logrotate.d
vi <app_name>

In the example below, we will rotate the Nginx logs in /apps/nginx/logs with the extension *.log.  It will happen daily and we will keep 14 days worth of logs.

The logs will be compressed with bzip2 using the –best option and we will change the owner of the .bz2 log file to be nginx:nginx.

/apps/nginx/logs/*.log {
daily
rotate 14
missingok
compress
compresscmd /usr/bin/bzip2
compressoptions –best
compressext .bz2
notifempty
create 0644 nginx nginx
sharedscripts
postrotate
/usr/bin/killall -HUP nginx &>/dev/null || :
endscript
}

1 Comment

1 Comment

  1. Burl Insogna

    June 13, 2010 at 2:59 am

    Hey

    i really found many nice articles on http://www.mytechforum.com/unix/how-do-i-rotate-and-compress-my-application-logs/

    Burl Insogna

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top