Colorize in Perl

In case you ever need to ‘colorize’ a log file from the command line…a guy at work (if he had a blog I’d link to it…nudge nudge) put this together:

use Term::ANSIColor;

while (<STDIN>)
{
if ($_ =~ /ERROR/) {
$color = “red”;
} elsif ($_ =~ /WARN/) {
$color = “magenta”;
} elsif ($_ =~ /DEBUG/) {
$color = “green”;
} else {
$color = “white”;
}
print color(${color});
print “$_”;
}

print color(”reset”);

Leave a Reply