On Wed, Nov 5, 2008 at 11:11,  <[EMAIL PROTECTED]> wrote:
> hi,
> I'm administering a server running apache/mod_perl.
> it runs a lot of old web applications who write to STDERR (print
> STDERR "log message...";).
> as they are a large number for me is a problem to find where the code
> is located, but I see a lot of lines of debugging in my apache error
> log.
> first of all I redirect all the debug messages to a new file putting
> the following line of code in global.asa Script_OnStart:
> open (STDERR, ">>/path/to/debug/log/file");
> what I'm not able to do is to automatically prepend the date to every
> entry in the debug log file (obviously without finding every print in
> the code....).
> any idea? maybe some parameters to pass to open?
snip

Well, it is a bit of a nasty hack, but you could say something like

#!/usr/bin/perl

use strict;
use warnings;

#open STDERR to a pipe to a Perl script that
#prepends the executable's name to every line
#and appends the line to a logfile
open STDERR, "|-", "perl -pe 's/^/$0 /' >> logfile"
        or die "could not open logfile: $!";

print STDERR "test1\n";
print STDERR "test2\n";
print STDERR "test3\n";


But you really should be using a standard logging function or module
instead.  I know it is a pain to retrofit the code, but it really is
the right answer in the long term.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to