jihuichoi

colortail perl script

May 9th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. while(<STDIN>) {
  4. my $line = $_;
  5. chomp($line);
  6. for($line){
  7. s/==>.*<==/\e[1;44m$&\e[0m/gi; #tail multiples files name in blue background
  8. s/\[ERROR\].*/\e[0;31m$&\e[0m/gi; #red : error
  9. s/\[INFO\].*/\e[0;90m$&\e[0m/gi; #blue
  10. s/\[DEBUG\].*/\e[1;34m$&\e[0m/gi; #green : debug
  11. s/\[warning\].*/\e[1;33m$&\e[0m/gi; #yellow :warning
  12.  
  13. }
  14. print $line, "\n";
  15. }
  16.  
  17. # color table : http://egloos.zum.com/sunyzero/v/4282610
  18.  
  19. #usage
  20. #tail a.log | color.pl
  21. #for convinience, add below line in ~/.bash_aliases
  22. #alias ctail='_(){ tail $@ | ~/linux_settings/bin/color.pl; }; _'
  23. #then use as $ ctail -f a.log
  24. #or for the lastest file in a directory
  25. #$ ctail -f `ls -t | head -1`
Advertisement
Add Comment
Please, Sign In to add comment