ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Previously, when on our old server, we used to be able to use this to print out to the perl_error_log (so we could track stuff in the code);
use Term::ANSIColor qw(:constants); print STDERR RED, "foo \n", RESET;

..and then when the code was run, it would print out the word "foo" in the perl_error_log, but in red.

However, since we upgraded the server to a more powerful one (with the same host), and I believe to the latest versions of Perl + Apache, we have got a bit of a problem!

The logs now come up like:

[Fri Mar 11 03:22:43 2011] [error] [client 90.200.254.240] \x1b[32mSub foo\x1b[0m

Which is absolutly no use to us :(

Is there any way of getting this to work on the latest version of Perl + Apache? (maybe with another module?)

UPDATE - this is interesting! It works fine in a basic perl script, just not when being show in the perl_error_log :/

Maybe some "escaping" is being done in those log files? Right PITA if it does!!! I also wanna get rid of the timestamp stuff in the error log, but it seems like we can't :(

UPDATE 2: Never mind - I found a work around. Simply doing:

open (STDERR,">>/var/home/voyage/voyageforum.com/logs/custom_logs") || die $!;

..and then the output is placed perfectly into that file, colouring and all!

TIA!

Andy

Replies are listed 'Best First'.
Re: Term::ANSIColor in Apache2?
by MidLifeXis (Monsignor) on Mar 11, 2011 at 14:34 UTC

    Apache logs now escape information sent to their log files. This is for good reason.

    I would also recommend not writing directly to the apache log files from your own application. Either write your own log file, or use the apache mechanism (STDERR), not both. Mixing your application writing directly to the log file that apache thinks it has exclusive rights to may lead to some hard to diagnose problems later on.

    What about setting up a reader for your log file that unescapes the data for each line before printing it?

    --MidLifeXis