Skip to content

Instantly share code, notes, and snippets.

@cybic
Created February 4, 2015 09:47
Show Gist options
  • Save cybic/9c37faa7ee768d51be4d to your computer and use it in GitHub Desktop.
Save cybic/9c37faa7ee768d51be4d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
#use Term::ANSIColor qw( :constants );
use Term::ANSIColor;
my %COL = (
'DEBUG' => color('magenta'),
'INFO' => color('blue'),
'WARNING' => color('yellow'),
'WARN' => color('yellow'),
'ERROR' => color('red'),
'DATE' => color('cyan'),
'UNKNOWN' => color('bold black')
);
my $RESET = color('reset');
while ( my $line = <> ) {
# Color log severity tags
if ( $line =~ m/^(.*?)\[(.*?)\s?\](.*)$/ ) {
my $COLCODE = $COL{$2} || $COL{'UNKNOWN'};
$line = "$1\[$COLCODE$2$RESET\]$3\n";
}
# Color timestamps
$line =~ s/(\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2},\d{3})/$COL{'DATE'}$1$RESET/g;
print $line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment