| Apache2-Tail documentation | Contained in the Apache2-Tail distribution. |
Apache2::Tail - mod_perl handler to display the error_log
PerlModule Apache2::Tail
<Location /tail>
SetHandler modperl
PerlHandler Apache2::Tail
[PerlSetVar Apache2::Tail::ErrorLog /some/other/log/file]
[PerlSetVar Apache2::Tail::CSS /css/mystyle.css]
[PerlSetVar Apache2::Tail::Count 100]
Order deny,allow
allow from 127.0.0.0/8
deny from all
</Location>
Simple mod_perl handler that displays a pretty html version of the error_log.
These options can be configured with PerlSetVar
The file to display, defaults to the current VirtualHost's error_log
The default maximum number of lines to display. Defaults to 50, but can also be overriden at request time with the ?n= query parameter
The URL to an alternate sylesheet, defaults to some built-in defaults
Quick summary of the internal APIs for anybody interested in subclassing Apache2::Tail.
The main handler, responsible for processing the request
Must return the full path to the file that needs tailing
prints the HTML header up to and including the <body> tag
returns the maximum number of lines to tail for this request.
returns the CSS content for the page
Philippe M. Chiasson <gozer@cpan.org>
Tara Gibbs <tarag@activestate.com>
http://svn.ectoplasm.org/projects/perl/Apache2-Tail/trunk/
Copyright 2007 by Philippe M. Chiasson <gozer@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
| Apache2-Tail documentation | Contained in the Apache2-Tail distribution. |
package Apache2::Tail; our $VERSION = 0.03; use strict; use warnings; 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"); <tr class="$level"><td class="timestamp">$date</td><td class="vhost">$name</td><td class="loglevel">$level</td><td class="client">$client</td><td class="message">$msg</td></tr> EOF last if --$tail_cnt <= 0; } $class->print_footer($r); return Apache2::Const::OK; } sub style { my ($class, $r) = @_; if (my $user_style = $r->dir_config($class . '::CSS')) { return qq(<link rel="stylesheet" type="text/css" href="$user_style">); } else { return <<'EOF'; <style type="text/css"> body { font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 10pt; color: #333333; } td { padding: .25em; align: top; background-color: #eee; } td.timestamp { font-size: 8pt; text-align: center; width: 130px; } tr.warn td { background-color: #FFE79F; } tr.error td { background-color: #FFCCCC; } tr.notice td { background-color: #DFE7FF; } .vhost { font-style: italic; } .loglevel { text-align: center; } tr.info td.loglevel { } tr.notice td.loglevel { color: #00C; font-weight: bold; } tr.debug td.loglevel{ } tr.warn td.loglevel { font-weight: bold; color: #FF803E; } tr.error td.loglevel { color: #F00; font-weight: bold; } .client { color: #333333; } .message { padding-left: .5em; } tr.error td.message, tr.warn td.message, tr.notice td.message { font-weight: bold; } </style> EOF } } sub print_footer { my ($class, $r) = @_; $r->print(<<'EOF'); </table></body></html> EOF } sub print_header { my ($class, $r) = @_; my $style = $class->style($r); $r->print(<<"EOF"); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Apache2::Tail $VERSION</title> $style </head> <body> <table border=0> EOF } sub tail_cnt { my ($class, $r) = @_; return $r->dir_config($class . '::Count') || TAIL_CNT(); } sub error_log { my ($class, $r) = @_; my $s = $r->server; return $r->dir_config($class . '::ErrorLog') || Apache2::ServerUtil::server_root_relative($r->pool, $s->error_fname); } 42; __END__