Forum OpenACS Q&A: Re: Large Error Logs

Collapse
5: Re: Large Error Logs (response to 4)
Posted by Jeff Davis on
I changed a lot of the more verbose and generally less useful notice messages to debug (or removed them entirely).

If you run a server with debug off your logs grow quite slowly now.

Collapse
6: Re: Large Error Logs (response to 5)
Posted by Bruce Spear on
Here's a little solution, in perl, written my buddy Manfred that might help you.

1. Create a logrotate file that archives the error.log daily on a 7 day rotation and notifies you via email.
2. Have cron run it daily

############################################################################
# logrotate.pl
############################################################################

# Rotieren der Logfiles

use File::Copy "mv";

$LOGFILE="error.log";
$LOGDIR="/usr/services/service0/log/";

($day, $mon, $year, $wday) = (localtime) [3,4,5,6];
($shh, $smm, $ssec) = (localtime) [2,1,0];
$mon += 1;
$year += 1900;

$datum = "$year$mon$day-$shh$smm$ssec";
$src = "$LOGDIR$LOGFILE";
$dst = "$LOGDIR$LOGFILE.$wday";

$MAILF = "/tmp/logrotate.$datum";
open (DEBUG, ">$MAILF") or die "$0: Can't create $MAILF $!\n";
print DEBUG "$0 Report to Bruce:\n";

print DEBUG "Operation starts: $shh:$smm:$ssec\n";
print DEBUG "mv $src $dst\n";
mv ($src, $dst) || die "$0: mv ($src, $dst) failed\nreason: $!\n";

$cmd = "/usr/local/bin/svc -h /usr/services/service0/etc/daemontools/";
@res = `$cmd`;
print DEBUG "Sending HUP signal to service.\n$cmd\n@res\n";
print DEBUG "success.\n";
close DEBUG;

fini();
exit;

sub fini {
        system ("/usr/bin/Mail -s \"[log] $day.$mon.$year \" mailto:boylston\@zedat.fu-berlin.de <$MAILF");
        unlink ($MAILF);
        exit 1;
}
~
~
##########################################################
nsd.cron.daily
##################
#!/bin/sh
/bin/su -c /usr/services/tools/logrotate.pl - service0
~
~