From d706ff3ebdb37aa2c2ed8fc30d5fb78f173b5f2b Mon Sep 17 00:00:00 2001 From: Michael S Collins Date: Fri, 28 Dec 2012 17:00:18 -0800 Subject: [PATCH] Simple perl script to colorize an existing FreeSWITCH log file; requires CPAN module Term::ANSIColor --- scripts/perl/fslog | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 scripts/perl/fslog diff --git a/scripts/perl/fslog b/scripts/perl/fslog new file mode 100755 index 0000000000..333017f493 --- /dev/null +++ b/scripts/perl/fslog @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# +# fslog +# +# colorizes output according to FS console log colors +# + +use strict; +use warnings; +use Term::ANSIColor qw(:constants);; +$|++; + +if ( $ARGV[0] && $ARGV[0] =~ m/--?h/i ) { + &usage; + exit(0); +} elsif ( $ARGV[0] && ! -f $ARGV[0] ) { + die "File not found: $ARGV[0]\n"; +} + +my $color_map = { + '[DEBUG]' => YELLOW, + '[INFO]' => GREEN, + '[NOTICE]' => CYAN, + '[WARNING]' => MAGENTA, + '[ERR]' => RED, + '[CRIT]' => RED, + '[ALERT]' => RED, +}; + +$SIG{INT} = sub { print RESET; }; + +while(<>) { + #print "Current line is: '$_'\n"; + if ( m/(\[(DEBUG|INFO|NOTICE|WARNING|ERR|CRIT|ALERT)\])/ ) { + print $color_map->{"$1"},$_,RESET; + } else { + print YELLOW,$_,RESET; + } +} + +print RESET; + +sub usage { + print <