Skip navigation

通过perl来给log里带有特殊单词的行加上颜色,带颜色的log更易于识别和阅读。

#!/usr/bin/env perl
while(<STDIN>) {
    s/($ARGV[0])/\033[1m\033[45m\1\033[0m/g if $ARGV[0];
    print "\033[1m\033[37m\033[41m" if /error/i;
    print "\033[1m\033[32m" if /info/i;
    print "\033[1m\033[32m" if /notice/i;
    print "\033[1m\033[36m" if /warn/i;
    print $_;
    print "\033[0m";
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>