SHARE
TWEET

saku log colorizer.

maya000 Aug 7th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env perl
  2. #
  3. # saku-log.pl - saku log colorizer.
  4. #
  5. #usage.
  6. # tail -f logfile | saku-log.pl
  7. #
  8. # grep foobar logfile | saku-log.pl | less
  9. #
  10.  
  11.  
  12. use strict;
  13. use warnings;
  14.  
  15. my $GREEN = "\e[36m";
  16. my $RESET = "\e[0m";
  17. my $IP    = "\e[32m";
  18. my $WARN  = "\e[33;1m";
  19. my $ERRNO = "\e[31;1m";
  20. my $INFO  = "\e[35;1m";
  21. my $UA    = "\e[96;1m";
  22. my $BASE  = $GREEN;
  23. my $ip_pattern = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{0,6})?';
  24.  
  25. while (my $line = <>) {
  26.     chomp $line;
  27.     $line = $BASE . $line . $RESET . "\n";
  28.     $line =~ s|<>|$RESET<>$BASE|g;
  29.     $line =~ s|($ip_pattern)|$RESET$IP$1$BASE|g;
  30.     $line =~ s|(<>\Q${BASE}\Etalk: http://)([^\d].+?)/|$1$RESET$IP$2$RESET$BASE/|;
  31.  
  32.     #info
  33.     $line =~ s|<>\Q${BASE}\E(shingetsu.+(started\|finished))|<>$INFO$1|;
  34.     $line =~ s|(client timeout)|$RESET$INFO$1$RESET|;
  35.     $line =~ s|<>\Q${BASE}\E(direct).+?m<>|<>\e[35m$1$RESET<>|;
  36.  
  37.     #warning
  38.     $line =~ s|Warning: |${WARN}Warning:$RESET |;
  39.     $line =~ s|(: records not found\.)|\e[33m$1$RESET|;
  40.     $line =~ s|(: too large or spam record.)|\e[33m$1$RESET|;
  41.     $line =~ s|(<urlopen error .+)|\e[31m$1|;
  42.     $line =~ s|<>\Q${BASE}\EIOError|<>IOError|;
  43.     $line =~ s|(\[Errno \d+\])|$ERRNO$1$RESET|;
  44.     $line =~ s|(: error)|\e[31m$1$RESET|;
  45.     $line =~ s|: (HTTP Error \d+:.+)|: $RESET\e[31m$1|;
  46.     #UA
  47.     $line =~ s|<>\Q${BASE}\E(shinGETsu.+?)(\(.+?\)).+?m$|<>\e[35m$1$RESET$2|;
  48.     $line =~ s|(\(.+?\))$|\e[34m$1$RESET|;
  49.     $line =~ s|<>\Q${BASE}\E(Mozilla/5.0 \(.+)|<>$UA$1|;
  50.     $line =~ s|<>\Q${BASE}\E(ia_archiver)|<>$UA$1|;
  51.     $line =~ s|<>\Q${BASE}\E(Python-urllib/.+)|<>$UA$1|;
  52.     print $line;
  53. }
  54.  
  55. print "$RESET";
  56.  
  57. __END__
RAW Paste Data
Top