#!/usr/bin/perl use strict; #------------------------------------------------------------------------------- our $logdir = "/var/log/apache2/confixx/domains/access"; our %filecache = (); our %logcache = (); our $alarm = 10; our $errorlog = ($ARGV[0] eq 'errorlog') ? 1 : 0; $SIG{ALRM} = \&on_alarm; #------------------------------------------------------------------------------- sub on_alarm { #print "ALARM!!!", $/; foreach my $logfile (keys(%logcache)) { #print "writing log for ", $logfile, $/; if (open(LOG, ">>" . $logfile)) { foreach my $logline (@{$logcache{$logfile}}) { print LOG $logline; } close(LOG); } delete($logcache{$logfile}); } alarm($alarm); } #------------------------------------------------------------------------------- alarm($alarm); while(my $line = ) { my ($domain, $log) = split(/:#?:/, $line, 2); $domain = lc($domain); #print "received log for ", $domain, $/; my $logfile; if (!defined($filecache{$domain})) { my $logfilelink = $logdir . "/" . $domain; next if (!-l $logfilelink); $logfile = readlink($logfilelink); $logfile =~ s/\/access_log/\/error_log/ if ($errorlog); $filecache{$domain} = $logfile; } else { $logfile = $filecache{$domain}; } #print "received log for ", $domain, " file=", $logfile, $/; #if (!$errorlog) #{ # $log =~ s/^(\d+\.\d+\.\d+)\.\d+ /$1.0 /; #} #else #{ # $log =~ s/\[client (\d+\.\d+\.\d+)\.\d+\]/\[client $1.0\]/; #} push(@{$logcache{$logfile}}, $domain . ' ' . $log); }