-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclftail
executable file
·74 lines (63 loc) · 1.62 KB
/
clftail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
# vim: ft=perl:
# abstract: color-follow-tail for access.log
use strict;
use File::Tail;
use Term::ExtendedColor qw(fg bg);
use Term::hr {
fg => 240,
pre => 8,
size => 72,
bold => 1,
};
my $log = shift // '/var/log/httpd/access_log';
my $tail = File::Tail->new(
name => $log,
maxinterval => 3,
adjustafter => 10,
interval => 10,
tail => 10,
);
my @keywords = qw(
devel
colorcoke
);
my $previous_ip = 0;
while(defined( my $line = $tail->read )) {
my $e = "(.+?)";
$line =~ /^$e $e $e \[$e:$e $e\] "$e $e $e" $e $e/;
my $ip = $1;
my $ref = $2;
my $name = $3;
my $date = $4;
my $time = $5;
my $gmt = $6;
my $request = $7;
my $file = $8;
my $ptcl = $9;
my $code = $10;
my $size = $11;
$code = fg(240, $code) if $code == 404;
$code = fg(155, $code) if $code == 200;
$code = fg(160, $code) if $code == 501;
$code = fg(208, $code) if $code == 301;
$code = fg(124, $code) if $code == 403;
$code = fg(113, $code) if $code == 304;
$request = fg(190, " $request") if $request eq 'GET';
$request = fg(196, " $request") if $request eq 'POST';
$request = fg(197, " $request") if $request eq 'CONNECT';
if($file =~ /\.(:?png|gif|jpg|jpeg)$/) {
$file = fg(167, $file);
}
elsif($file =~ /\.html$/) {
$file = fg(74, $file);
}
else {
$file = fg(222, $file);
}
$size = fg(160, $size) if $size > 5;
printf("%s %7s %s \e[38;5;215m%s\e[0m \t%-60s\n",
$code, $request, $size, $ip, $file) unless $file =~ m/.+\.(?:css|ico)$/;
printf "%s\n", hr() if $previous_ip ne $ip;
$previous_ip = $ip;
}