Skip to content

Instantly share code, notes, and snippets.

@cedricvidal
Created November 8, 2012 10:51
Show Gist options
  • Save cedricvidal/4038126 to your computer and use it in GitHub Desktop.
Save cedricvidal/4038126 to your computer and use it in GitHub Desktop.
Simple PERL colorizer
#!/usr/bin/perl -w
use Term::ANSIColor;
use POSIX qw(strftime);
use Getopt::Long;
Getopt::Long::Configure("no_ignore_case");
%colors = (
'DEBUG' => 'yellow',
'INFO' => 'green',
'WARN' => 'cyan',
'ERROR' => 'red',
'FATAL' => 'red',
);
# main loop
while(<STDIN>) {
chomp($_);
local $line = $_;
my $matched = 0;
my $selected;
while ((($pattern, $color) = each(%colors)) && !$selected)
{
if($line =~ /($pattern)/) {
$selected = $color;
}
}
keys %colors;
if(!$selected) {
$selected = 'white';
}
print colored($line, $selected), "\n";
}
# vim: ts=4:sw=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment