Thursday, August 25, 2011

Housekeep Asterisk Log Files

Asterisk log files can grow very large unawared, eventually leading to disk space problems. 
We can take a few measures to maintain log history and housekeep old ones automatically.
1.    Review the /etc/asterisk/logger.conf
This file specifies the logging level of asterisk.  In a production system, it is sufficient to turn on message log only while keeping the others disabled. 
;debug => debug
console => notice,warning,error,debug
messages => notice,warning,error
;full => notice,warning,error,debug,verbose
The modified logging level is made effective by:
asterisk –rx 'logger reload'
2.    Use logrotate to rotate and remove historical files
This utility is helpful in housekeeping outdated log files.  The logrotate is usually invoked from /etc/cron.daily and it looks for how and what to process in the /etc/logrotate.conf.
As illustrated in the logrotate.conf below, we rotate log files on weekly basis and keep 4 weeks.  Rotated log would have a timestamp as suffix.  Older files would be deleted automatically.  Note that we can compress rotated files to further reduce disk usage.  Individual rotation information are put in /etc/logrotate.d.
# see "man logrotate" for details
# rotate log files weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
# use date as a suffix of the rotated file
# uncomment this if you want your log files compressed
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
In /etc/logrotate.d/, we can create a file (eg, named as 'asterisk') to specify which asterisk log files we want to housekeep.  We need to run 'logger reload'.  Otherwise, Asterisk still writes to the old file.
/var/log/asterisk/messages  {
    /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null

1 comment:

  1. Very inspirational post. I used to love to take walks, but I would let my mind “trick” me into thinking that “just today, I should rest, but I’ll walk tomorrow.”
    Eventually I stopped doing my walks. But reading your post it looks like you are totally motivated! That’s cool! If I may ask about this posting.
    cheap hosting reviews