2
0

fslog 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl
  2. #
  3. # fslog
  4. #
  5. # colorizes output according to FS console log colors
  6. #
  7. use strict;
  8. use warnings;
  9. use Term::ANSIColor qw(:constants);;
  10. $|++;
  11. if ( $ARGV[0] && $ARGV[0] =~ m/--?h/i ) {
  12. &usage;
  13. exit(0);
  14. } elsif ( $ARGV[0] && ! -f $ARGV[0] ) {
  15. die "File not found: $ARGV[0]\n";
  16. }
  17. my $color_map = {
  18. '[DEBUG]' => YELLOW,
  19. '[INFO]' => GREEN,
  20. '[NOTICE]' => CYAN,
  21. '[WARNING]' => MAGENTA,
  22. '[ERR]' => RED,
  23. '[CRIT]' => RED,
  24. '[ALERT]' => RED,
  25. };
  26. $SIG{INT} = sub { print RESET; };
  27. while(<>) {
  28. #print "Current line is: '$_'\n";
  29. if ( m/(\[(DEBUG|INFO|NOTICE|WARNING|ERR|CRIT|ALERT)\])/ ) {
  30. print $color_map->{"$1"},$_,RESET;
  31. } else {
  32. print YELLOW,$_,RESET;
  33. }
  34. }
  35. print RESET;
  36. sub usage {
  37. print <<EOT
  38. fslog reader
  39. Feed me a FreeSWITCH log file and I will colorize the output
  40. fslog freeswitch.log
  41. -OR-
  42. grep foo freeswitch.log | fslog | more
  43. NOTE: some versions of more and less do not support colorized text.
  44. EOT
  45. }