'logger rotate' and logrotate
Asterisk logs files (typically under /var/log/asterisk) need some attention because they can get quite large.You can do "logger rotate" from the asterisk command line or
/usr/sbin/asterisk -rx 'logger rotate'
from a bash prompt .. and you can add it to a cron job so it does it automatically for you.
logrotate
If however you have a system that uses the logrotate utility, you can get it to rotate without making a special script and you can still have good control over what the system does with your logs.Here is a sample from /etc/logrotate.d/asterisk on my system
/var/log/asterisk/messages /var/log/asterisk/*log {
missingok
rotate 5
weekly
create 0640 asterisk asterisk
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}
This setup will rotate the files weekly cycling them 5 times so for example, messages will be the newest log file, followed by messages.1, messages.2 all the way to messages.5 (the oldest). If you are not running asterisk as user:group asterisk:asterisk, you can eleminate the
create 0640 asterisk asterisk line.
If you're just keeping cdr records in csv files and you're just using them to check against VOIP providers charges (so accuracy isn't a big concern) you can use this logrotate script to rotate them once a month
/var/log/asterisk/cdr-csv/*csv {
missingok
rotate 5
monthly
create 0640 asterisk asterisk
}
logrotate for Debian
You'd still need to command asterisk 'logger reload' just after moving the log file, or otherwise it will continue to write to the old file.The current default Debian /etc/logrotate.d/asterisk is:
/var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/debug /var/log/asterisk/event_log /var/log/asterisk/messages {
weekly
missingok
rotate 4
sharedscripts
postrotate
/usr/sbin/invoke-rc.d asterisk logger-reload
endscript
}
See also
Go back to Asterisk
Comments
333Should postrotate be lastaction instead?
logrotate -d /etc/logrotate.d/asterisk
you'll see that the postrotate command gets executed once per file that is rotated. Is this necessary? Does Asterisk need to reload logging once per file or can it be done only once, at the end of the set of rotations?