#!/usr/bin/perl
use strict;
my $reset = "\e[0m";
my $bold = "\e[1m";
my $c = 0;
my @colscheme=qw(brblue cyan cyan red brgreen brred brmagenta green yellow);
my %colour = map {
$_, ("$reset\e[" . (31+$c) . 'm'),
"br$_", ("$reset$bold\e[" . (31+$c++) . 'm'),
} qw(red green yellow blue magenta cyan white);
print $reset . $colour{white};
while (<>) {
chop;
my @a = parse_line($_);
print "$colour{brred}FAIL PARSING $_$colour{white}" unless scalar @a;
for my $c (@colscheme) {
my $e = shift @a;
$e =~s/(\w?)(\W)(\w?)/$1$reset$2$colour{$c}$3/g unless length $e == 1;
print "$colour{$c}$e ";
}
print "\n";
}
sub parse_line {
return ($_[0]=~m/^
(\d+\.\d+\.\d+\.\d+|[a-z0-9\:]+)\s+ # ipv4|6, space
(\S+)\s+ # remote log name, from identd, space
(\S+)\s+ # remote http auth name
\[(\d+\/\w+\/\d+\:\d+\:\d+\:\d+\s+\+\d+)\]\s+ # date, time
\"(.*?)\"\s+ # method, request
(\d+)\s+ # response code
(\d+|\-)\s+ # size
\"(.*?[^\\]?)\"\s+ # referrer
\"(.*?[^\\]?)\" # useragent
/x);
}