13.2. Managing Logs

Asterisk activity generates events that will cause the creation of an entry in either the main system logs, or in asterisk's own log files. On a busy system (or a system that is experiencing a severe problem), these log files can grow very large, very fast. If debugging is turned on, the processes involved in writing to these log files can begin to have an effect on system performance. By default, Asterisk will simply add to the files until the hard drive is full. Fortunately, Linux provides utilities to handle the rotation of log files (so that no single file becomes too large), and also the deletion of older log files (which will prevent the system from getting clogged with log files).

The logrotate utility is normally run once per day by the operating system. Unfortunately, since there is no script installed to instruct logrotate on how to handle Asterisk, its log files will grow unchecked until a rotate script is added to handle them. In order to make that happen, we need to set up parameters for asterisk under the /etc/logrotate.d directory, This file will need to rotate the current log file, and then send asterisk an instruction to rotate it's own logger (causing it to stop using the now old log file, and genereate a new file).

Create a new file /etc/logrotate.d/asterisk and place the following lines in it:

/var/log/asterisk/* /var/log/asterisk/cdr-csv {
    missingok
    sharedscripts
    monthly
    rotate 12
    postrotate
        asterisk -rx "logger rotate" > /dev/null 2> /dev/null
    endscript
}

This file tells the logrotate utility to rotate the asterisk logs every month, save 12 months worth of logs, and then tell asterisk that the log files have been rotated (which will cause asterisk to create new log files and begin writing to them). We selected these values arbitrarily. Feel free to adjust them to suit your needs.