Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.5: Allow the system.log file to be rotated daily' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Allow the system.log file to be rotated daily
Authored by: rflorence on Dec 19, '07 12:51:28PM
Launchd actually runs newsyslog every hour, on the hour. It is because of the default configuration in /etc/newsyslog.conf and a quirk in newsyslog (it will not run a skipped event more than one hour after it was originally scheduled) that the default setup only rotates system.log within an hour of midnight.

It will work to rotate system.log by size, but Unix systems traditionally rotate system.log daily to make the search for error messages simpler.

Finally, newsyslog.conf cannot be used to rotate the other files that eventually grow unwieldy, like daily.out, weekly.out, the apache2 logs, and even fsck_hfs.log. Instead, try a script like

# script to rotate logs

rotatelog ()
    size=`ls -l $log | awk '{print $5}'`
    if [ $size -gt 50000 ] 
        bzip2 < $log > $log.0.bz2 
        chmod 0644 $log.0.bz2
        > $log

newlog ()
    [ -f $log.2.bz2 ] && mv $log.2.bz2 $log.3.bz2
    [ -f $log.1.bz2 ] && mv $log.1.bz2 $log.2.bz2
    [ -f $log.0.bz2 ] && mv $log.0.bz2 $log.1.bz2
    bzip2 < $log > $log.0.bz2 
    chmod 0644 $log.0.bz2
    > $log

cd /var/log
rotatelog daily.out
rotatelog weekly.out

cd /var/log/apache2
newlog access_log
newlog error_log
as /etc/weekly.local or /etc/monthly.local.

[ Reply to This | # ]