#
# $Id: ApacheErrorlog.pm,v 1.3 2002/03/14 10:14:11 fpmip Exp $
#

# Author : Tycho Fruru <tycho@fruru.com>

# Copyright (C) 2001 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001 Conostix S.A. Luxembourg - Tycho Fruru <tycho@conostix.com>

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#

package IPFC::Parse::Event::ApacheErrorlog;

use strict;
use warnings;
use IPFC::Log;

my $LAST_TIME;

sub parse($$) {
	shift; # current class
	my $apache_line = shift;
	my $template_event = shift;
	
	# make local copies so that we don't pollute the global variables
	my $event = $template_event->clone;
	
	my $rc = 1;
	
	$event->replace_attributes({ 'message'  => $apache_line });
			
	if ($apache_line =~ /^\[([^\]]+)\] .*$/) {
		$event->replace_attributes({ "time" => $1 });
		$LAST_TIME=$1;
	} else {
		if (defined($LAST_TIME)) {
			$event->replace_attributes({ "time" => $LAST_TIME });
			#IPFC::Log::logger(4,"Apache error line $decoded_apache_line not acceptable in entry nr. $index\n");
		}
	}
			
	IPFC::Log::logger(10,"End of process_apache_error_log_1, return $rc");
	
	return $event; # 1 is ok, 0 is not ok
}

return 1;
