Showing posts with label perl highlight console logs glassfish color pipe tail grep. Show all posts
Showing posts with label perl highlight console logs glassfish color pipe tail grep. Show all posts

Wednesday, September 24, 2008

console highlighter

i've been squinting at my glassfish log tails for far too long now. i decided to write a small script that would highlight rows containing particular keywords.

this script will show error messages in red, and warning messages in yellow:

#!/usr/bin/perl

use strict;
use Term::ANSIColor;

while (<stdin>){
if ($_ =~ m/(exception|error)/i){
print color 'bold red';
print $_;
print color 'reset';
}elsif ($_ =~ m/(warning)/i){
print color 'bold yellow';
print $_;
print color 'reset';
}else{
print $_;
}
}
this was pretty straight forward and can be easily modified. to use this, i put this in a script called highlighter.pl, and pipe my logs through it:

tail -F server.log | ~/bin/highlighter.pl