Ubuntu 14.04+ and Asterisk 13: Rotating Logs

After a while, Asterisk can spit out a lot of logging, which eventually will take up a large amount of room. Thankfully Ubuntu already has a program installed by default to help get a handle on logs called “logrotate.” This makes it really simple to add more logs to be rotated. Simply create the file below and add in the logs you want to rotate:


/var/log/asterisk/messages /var/log/asterisk/debug /var/log/asterisk/queue_log {
        rotate 7
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2>&1

Done! By default, logrotate is scripted to run daily (as seen under /etc/cron.daily).

To take a quick look, this is what the script does:

1st line consists of one or more log paths. The options will apply to all of the logs specified.
missingok – If the log file is missing, go on to the next one without issuing an error message.
rotate 7 – Log files are rotated times before being removed.
notifempty – Do not rotate the log if it is empty.
daily – Logs are rotated daily.
The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed after the log file is rotated. The command in the middle tells Asterisk to reload the logger module which re-creates the files.