Leser: 23
1
2
3
4
5
6
7
8
9
10
log4perl.logger = DEBUG, Rotator
log4perl.appender.Rotator = Log::Dispatch::FileRotate
log4perl.appender.Rotator.name = file1
log4perl.appender.Rotator.min_level = debug
log4perl.appender.Rotator.filename = Somefile.log
log4perl.appender.Rotator.mode = append
log4perl.appender.Rotator.max = 7
log4perl.appender.Rotator.TZ = CET
log4perl.appender.Rotator.DatePattern = yyyy-MM-dd
log4perl.appender.Rotator.layout = SimpleLayout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
my $MAXSIZE = 1024*1024; my $DEBUG = 0; sub RotateLog { my $filename = shift; my $MAXCYCLE = shift || 10; if ( -e "$filename.$MAXCYCLE" ) { foreach my $gz ( '/bin/gzip', '/usr/bin/gzip', '/usr/local/bin/gzip', undef ) { last if ( not defined $gz ); if ( -x $gz ) { system("$gz -c $filename.$MAXCYCLE >> $filename.gz"); last; } } } for ( my $s = $MAXCYCLE - 1 ; $s >= 0 ; $s-- ) { my $oldname = $s ? "$filename.$s" : $filename; my $newname = join( ".", $filename, $s + 1 ); if ( -e $oldname ) { warn("RotateLog: $oldname--\>$newname\n") if $DEBUG; rename( $oldname, $newname ) or warn("RotateLog: $oldname not renamed to $newname\n"); } } 1; } ... # irgendwo im Skript my ($fsz) = (stat($logfile))[7]; RotateLog($logfile) if ( $fsz >$MAXSIZE );