lehr88
lehr88

Reputation: 29

color the log output (stdout) in perl

I'm sorry for typos
i have a log file like this:

mynum[85295365] | yournum[3201410] | mymessage[4 ????? 4 off] | MSGLen[1]

i would coloring output like this

mynum == foreground blue  
yournum == foreground yellow  
and mymessage == foreground green.

i have a problem for coloring mymessage.
I tried the following code:

if($currentLine=~m/mymessage\[([\w+\d+\S]+){1,}\]/){  
$mymessage=$1;  
$outM="$mymessage";  
$currentLine=~s/mymessage\[([\w+\d+\S]+){1,}\]/mymessage[$cg$outM$crs]/g;}

and no result did not.
help me :(((((

Upvotes: 1

Views: 298

Answers (2)

Toto
Toto

Reputation: 91488

Use this regex:

mymessage\[(.+?)\]

Then your code becomes:

if ($currentLine =~ /mymessage\[(.+?)\]/) {
    $mymessage = $1;  
    $outM = $mymessage;  
    $currentLine =~ s/mymessage\[(.+?)\]/mymessage[$cg$outM$crs]/g;
}

Upvotes: 0

Miguel Prz
Miguel Prz

Reputation: 13792

use the Term::ANSIColor CPAN module. It allows you to color screen output using ANSI escape sequences

Upvotes: 1

Related Questions