ログのフィルタリングの履歴

簡単だけど、こんな感じでスクリプトを作っておくと便利

#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use constant    C_ERROR =>      "\x1b[31m";
use constant    C_INFO  =>      "\x1b[46;34m";
use constant    C_DEBUG =>      "\x1b[32m";
use constant    C_SURVEY=>      "\x1b[35m\x1b[44m";
use constant    C_RET   =>      "\x1b[m";
use constant    C_SQL   =>      "\x1b[47m\x1b[34m";

use constant    C_SQL_M =>      "\x1b[48;5;234m\x1b[38;5;240m";
use constant    C_IGNORE        =>      "\x1b[38;5;233m";

while ( <> ) {
        $_ =~ s/(error)/C_ERROR().$1.C_RET()/ige;
        $_ =~ s/(PHP Warning)([^a-z])/C_ERROR().$1.C_RET().$2/ge;
        $_ =~ s/(info)([^a-z])/C_INFO().$1.C_RET().$2/ige;
        $_ =~ s/(PHP Notice)([^a-z])/C_INFO().$1.C_RET().$2/ge;
        $_ =~ s/(debug)/C_DEBUG().$1.C_RET()/ige;
        $_ =~ s/(survy)/C_SURVEY().$1.C_RET()/ige;
        $_ =~ s/(INSERT|DELETE|UPDATE|CREATE|DROP)( [^;]+)/C_SQL().$1.$2.C_RET()/ige;
        $_ =~ s/(SELECT)( [^;]+)/C_SQL_M().$1.$2.C_RET()/ige;
        $_ =~ s/(referer: .*)$/C_IGNORE().$1.C_RET()/ige;
        print $_;
}


"error"や"debug"の文字が出てくるとそこだけ着してくれる。

プチ便利

追記[2009.8.6]: だんだんよくわからないハッカーっぽくなってきてしまった…