0: #!perl
1: # 1. errorlog.pl parses and displays apache errorlogs
2: # 2. just change $error_log and $apache to your paths
3: # 3. cookies remember the list size and filter status
4:
5: use strict;
6: use CGI qw(:standard);
7: use CGI::Cookie;
8: use HTML::Entities;
9:
10: my$error_log = 'c:\path\to\error.log'; # CHANGE
11: my$apache = 'c:\path\to\Apache\Apache.exe: '; # CHANGE but, leave space at end.
12: my$show = 10; # default number of errors to show
13: my@EL = stat $error_log;
14:
15: my%cookies = fetch CGI::Cookie;
16: my%i = map{$_ => param($_)} param;
17: my$url = url();
18: my$time = localtime();
19: $time =~s| .{4}$||o;
20:
21: open (ELOG,"<".$error_log) or die "$!";
22: my@elog=<ELOG>;
23: close (ELOG) or die "$!";
24:
25: my($cc,$c1,$c2);
26:
27: if($cookies{'show'}){
28: unless($i{'n'}=~/\d+/){
29: $show = $cookies{'show'}->value;
30: }
31: }
32: if($i{'n'}=~/\d+/){
33: $show=$i{'n'};
34: $c1 = new CGI::Cookie(-name=>'show',-value=>"$show",-expires=>'+1y');
35: }
36: if(($cookies{'clean'}=~/yes/) or ($i{'do'}=~/clean/)){
37: if($i{'do'}=~/clean/){
38: $c2 = new CGI::Cookie(-name=>'clean',-value=>'yes',-expires=>'+1y');
39: }
40: $cc=' checked';
41: }
42: if(($i{'go'}=~/show/) && ($i{'do'}!~/clean/)){
43: $c2 = new CGI::Cookie(-name=>'clean',-value=>'no',-expires=>'+1y');
44: $cc=();
45: }
46:
47: print header(-cookie=>[$c1,$c2]);
48: print<<HTML;
49: <html><head>
50: <title>$show Recent $ENV{'SERVER_NAME'} Server Errors</title>
51: <SCRIPT LANGUAGE="JavaScript"><!--
52: function me(){
53: document.forms[0].elements[0].select();
54: document.forms[0].elements[0].focus();}
55: //--></SCRIPT></head>
56: <body bgcolor="#c0c0c0" text="#000000" onload="me()">
57: <table border="0" cellpadding="0" cellspacing="0" width="100%">
58: <tr><form method="post"><td>
59: <h3>$show Recent <a href="http://$ENV{'SERVER_NAME'}/">
60: $ENV{'SERVER_NAME'}</a> Server Errors<br>
61: <font size="-1">$time</font><br></h3></td>
62: <td align="right"><small>
63: clean</small><input type="checkbox" name="do" value="clean"$cc>
64: <input type="text" name="n" value="$show" size="3" maxlength="4" onfocus="select()">
65: <input type="submit" name="go" value="show"></td>
66: <td rowspan="2"> </td></form></tr></table>
67: <hr>
68: HTML
69: @elog=reverse(@elog);
70: my$c=0;
71: foreach my $ln(@elog){
72: unless($c==$show){
73: &encode_entities($ln);
74: $ln=~s|\Q$apache||oi;
75: if($cc=~/checked/){
76: $ln=~s/\s\[(?:notice|error|warn)\]\s\[client.*\]//o;
77: $ln=~s/\s2\d{3}]/\]<br>/o;
78: $ln=~s/\[/<small><b>/o;
79: $ln=~s|\]|</b></small>\n|o;
80: }
81: print $ln.'<hr>';
82: $c++
83: }
84: }
85: print<<HTML;
86: <table width="100%"><tr><td colspan="2" align="right"><font size="-1">
87: <a href="file://$error_log">$error_log</a> = $EL[7] bytes</td></tr></table></body></html>
88: HTML
89: exit
In reply to apache errorlog by epoptai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |