星期一, 1月 31, 2005

copy from perl cookbook

Here's some example code that uses these parameters:

use Logfile::Rotate;
$logfile = new Logfile::Rotate(
File => "/var/adm/log/syslog",
Count => 5,
Gzip => "/usr/local/bin/gzip",
Signal =>
sub {
open PID, "/etc/syslog.pid" or
die "Unable to open pid file:$!\n";
chomp($pid = );
close PID;
# should check validity first
kill 'HUP', $pid;
}
);
This locks the log file you've specified and prepares the module for rotating it. Once you've created this object, actually rotating the log is trivial:

$logfile->rotate( );
undef $logfile;