package Apache2::Tail; our $VERSION = 0.02; use strict; use Apache2::RequestIO (); use Apache2::RequestRec (); use Apache2::ServerUtil (); use Apache2::ServerRec (); use File::Tail (); use CGI; use Apache2::Const -compile => qw(OK); use constant TAIL_CNT => 25; sub handler : method { my $class = shift; my $r = shift; my $s = $r->server; my $name = $s->server_hostname; my $error_log = $class->error_log($r); my $q = new CGI($r); my $tail_cnt = $q->param('n') || $class->tail_cnt($r); $r->content_type('text/html'); my $tail = File::Tail->new( name => $error_log, tail => $tail_cnt, nowait => 1, ); $class->print_header($r); while (my $line = $tail->read) { my ($date, $level, $client, $msg); if ($line =~ m{\[(.*?)\]\s*\[(.*?)\]\s*(\[client\s*(.*?)\]\s*)?(.*)}) { $level = $2; $date = $1; $client = $4; $msg = $5; $msg =~ s/\\t/ /g; } next unless $date; $r->print(<<"EOF");