Page tree
Skip to end of metadata
Go to start of metadata

Default log retention times

By default, FreePBX Distro is configured to keep a seven day history for most Asterisk log files.

This is not necessarily long enough to troubleshoot issues going back in time, especially for clients that look at their phone bills once a month or when trying to find a pattern to rare call error events.

Configure log retention times

Log file retention is set through the configuration file /etc/logrotate.d/asterisk. The following example increases log file retention to 60 days.

vi /etc/logrotate.d/asterisk
  • Edit the file to set the log rotation period to 60 days and add compression for the second group of log files
/var/log/asterisk/queue_log {
        daily
        missingok
        # Customization: increase log retention time from the default 30 days to 60 days
        #rotate 30
        rotate 60
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
}
/var/spool/mail/asterisk
/var/log/asterisk/freepbx_debug.log
/var/log/asterisk/messages
/var/log/asterisk/event_log
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban {
        daily
        missingok
        # Customization: increase log retention time from the default 7 days to 60 days
        #rotate 7
        rotate 60
        # Customization: compress log files to save disk space
        compress
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
        endscript
}

The logrotate program will pick up on the changes the next time it runs and keep a longer log history in the future.

Disk space considerations

Note that the each day's "full" log file can be several megabytes large (depending on PBX call volume).

The addition of the line "compress" to the section of logrotate commands (as in the example above) causes the affected log files to be compressed with gzip.

The zgrep command can be used just like the grep command, but will transparently search both compressed and uncompressed log files

Configuring log rotation for additional FreePBX log files

There are some FreePBX log files not rotated in the default FreePBX Distro configuration. If desired, the following can be added to the end of /etc/logrotate.d/asterisk to ensure these files are trimmed back at regular intervals.

vi /etc/logrotate.d/asterisk
  • Add the following content to the end of the /etc/logrotate.d/asterisk file to add log rotation for the specified log files
...

/var/log/asterisk/freepbx_dbug
/var/log/asterisk/freepbx_debug
/var/log/asterisk/freepbx.log {
        # rotate the above log files each month, keeping a six month log history and compressing log files
        monthly
        missingok
        rotate 6
        compress
        notifempty
        create 0640 asterisk asterisk
}
  • No labels

4 Comments

  1. Hi Tim, what's about freepbx.log? could we manage its retention/rotation too as done for various other Asterisk log files (and for freepbx_debug.log too) as reported? or...Am I missing something special about freepbx.log that I didn't see before? hope not.

  2. Hi parnassus, sure. I added in an example that does monthly rotation for the log files not rotated in the default FreePBX Distro configuration.

  3. Great Tim! just one question (out of scope?): what's the function of the logger reload procedure (postrotate/endscript) configured only on the fail2ban section?  Davide.

    P.S. a way to test logrotate's behaviour with defined rotation/retention rules of Asterisk/FreePBX log files is to perform a logrotate -d -f /etc/logrotate.d/asterisk and look its result.

  4. Asterisk has an open file handle to some of these log files. The logger reload command to Asterisk tells it to close any connections to (open) log files and create new versions of these log files. As the original files have been renamed by this point by logrotate, the effect is to open a new log file with the original name after log file rotation.