#!/usr/local/bin/perl # -*- perl -*- # Copyright (c) 2001 by Jeff Weisberg # Author: Jeff Weisberg # Function: colorize logfile output # typical use: # tail -f logfile | red -g something & # tail -f logfile | red -g otherthing -blue & use Getopt::Long; $color = "1;31"; $attr = ''; GetOptions( "g=s@" => \@grep, "v=s@" => \@expt, "i" => \$opt_i, "red" => sub { $color = "1;31" }, "blue" => sub { $color = "1;34" }, "green" => sub { $color = "32" }, "purple" => sub { $color = "1;35" }, # technically this is "magenta" "magenta"=> sub { $color = "1;35" }, # we allow either name... "cyan" => sub { $color = "36" }, "yellow" => sub { $color = "33" }, "none" => sub { $color = "30" }, "blink" => sub { $attr .= "5;" }, # not implemented in xterm "reverse"=> sub { $attr .= "7;" }, "underline" => sub { $attr .= "4;" }, "color=s"=> sub { shift; $color = shift; }, "help|?" => \&usage, ); $| = 1; LOOP: while(<>){ chop; if( $opt_i ){ foreach $v (@expt){ next LOOP if /$v/i }; foreach $g (@grep){ next LOOP if !/$g/i }; }else{ foreach $v (@expt){ next LOOP if /$v/ }; foreach $g (@grep){ next LOOP if !/$g/ }; } print "\e\[${attr}${color}m$_\e\[0m\n"; } sub usage { print STDERR <