Go to the documentation of this file.00001 package MMAgic::Log::Parser::Apache;
00002 #
00003 # MMAgic/Log/Parser/Apache.pm
00004 #
00005 # Parser for normal Apache log files.
00006 #
00007
00008 use UNIVERSAL qw(isa);
00009
00010 use MMAgic::Log;
00011 use MMAgic::Log::Parser;
00012 use MMAgic::Trace;
00013
00014 @ISA = qw(MMAgic::Log::Parser);
00015
00016 #!# Log->trace('Loading class ', __PACKAGE__);
00017
00018 ###########################################################################
00019 ###########################################################################
00020 sub parse # $self, $line [, $unrec ]
00021 #
00022 {
00023 my $self = shift;
00024 #!# my $auto = Log->method(@_)->block;
00025 my $line = shift;
00026 my $flag = '?';
00027 my $date = undef;
00028
00029 if ($line =~ /^\s*\[([^\[\]]*)\]\s*\[([a-zA-Z]*)\]\s*(.*)$/)
00030 {
00031 $date = $1;
00032 $flag = $2 eq 'notice' ? 'I' :
00033 $2 eq 'warn' ? 'W' :
00034 $2 eq 'error' ? 'E' : '?';
00035 $line = $3;
00036
00037 if ($date =~ m|[\S]+\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)|)
00038 {
00039 # Try to avoid using the Date::Manip functions (they're slow):
00040 $date = $self->makeTime($date, $5, $4, $3, $2, $1, $6);
00041 }
00042
00043 else
00044 {
00045 # Oh, well, better to go for it slowly than not at all:
00046 $date = $self->makeTime($date);
00047 }
00048
00049 Log->warning('Unknown flag on Apache line: ', $2) if $flag eq '?';
00050 }
00051
00052 elsif ($line =~ /Apache server shutdown initiated.../)
00053 {
00054 $date = $self->lastDate;
00055 $flag = 'C';
00056 }
00057
00058 elsif ($line =~ /Failed loading.*No such file or directory/)
00059 {
00060 $date = $self->lastDate;
00061 $flag = 'E';
00062 }
00063
00064 else
00065 {
00066 if (my $unrec = shift())
00067 {
00068 $unrec->warning('Unrecognizable Apache ', $self->name,
00069 " line:\n ", $line);
00070 }
00071
00072 return $self->SUPER::parse($line, $unrec);
00073 }
00074
00075 # Log->warning('No Apache date from ', $self->name),
00076 $date = $self->lastDate
00077 unless int($date);
00078
00079 $flag = 'I'
00080 if $line =~ /FastCGI.*started/
00081 or $line =~ /FastCGI.*terminated/;
00082
00083 ( $date, $flag, $line )
00084 }
00085
00086 1