Configure Asterisk log file retention
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