ログに色

練習(笑)
apacheのログをカラフルに。

#!/usr/bin/perl -w
use strict;

# 30..37 テキスト  黒 赤 緑 黄 青 紫 水 白
# 40..47 背景色

my @colors = qw(34 31 33 34 32 31);

while(<>) {
  my $cnt = -1;
  s/([^"\[\] ]+|".*?"|\[.*?\])(\s)/
        $cnt++; "\x1b[$colors[$cnt%@colors]m$1\x1b[m$2"/ge;
  print ;
}

実行結果。