# usage: # http://host/path/velog.cgi will show the lines in the error log # you haven't seen yet. # http://host/path/velog.cgi?all=234 will show all the lines in the #### #!perl -wT #config variables my $logfile = q(D:\httpd\Apache\logs\error.log); my $initial = ""; #first line of each error my $subseq = ""; #additional lines for each error my $domain = ""; my $path = ""; my $expires = ""; my $cookiename = "veloglastline"; use strict; use CGI; use Text::Wrap; #returns a CGI::cookie that looks something like veloglastline=#### #where #### is the last line of the error log viewed. sub makecookie { my $q = shift; my $line = shift; my $cookie = $q->cookie( { -name => $cookiename, -value => $line, -domain => $domain, -expires => $expires, -path => $path } ); return $cookie; } #checkes for a CGI::cookie that looks something like veloglastline=#### #where #### is the last line of the error log viewed. #defaults to 0 (ie, show the entire error log) sub getlastlineviewed { my $q = shift; my $cookie = $q->cookie($cookiename) || 0; my $line; if($cookie =~ m/^(\d*)$/) { $line = $1; }else{ $line = 0; } return $line; } #gets the last $lastline lines from the errorlog, and returns a REFERENCE #to an array of the last lines. sub getlogtext { my $q = shift; my $lastline = shift; my @lines; open (ELOG, "<$logfile") or die "unexpected error opening error log for reading: $!\n"; #intentionally toss away these lines. while((!eof(ELOG)) && ($. < $lastline)); if(eof) { @lines = ("No unread lines found"); }else { @lines = ; #slurp in the rest of the lines. } close ELOG; return \@lines; #return a REFERENCE to the array! } #takes a reference to a CGI object, the total number of lines in the errorlog #and a reference to an array of text. Sets a cookie with the number of lines #read along, and prints the text inside
 tags.
#this may change to plain text in the near future.
sub printerrorlog {
  my $q = shift;
  my $lastline = shift;
  my $text = shift;
  my $cookie = makecookie($q, $lastline);

  print $q->header(-type => "text/plain", -cookie => $cookie),
        wrap($initial, $subseq, @$text);
}

my $q = CGI->new();
my $startline;
my $lastline;
my $logtext;

$startline = getlastlineviewed($q);
$startline=0 if(defined($q->param("all")));
$logtext = getlogtext($q, $startline);
$lastline = $startline + $#$logtext;
printerrorlog($q, $lastline, $logtext);