in reply to Formatting STDERR

merlyn has a nifty routine for that, which I shamelessly stole for Simple HTTP in under 100 lines :

$SIG{__WARN__} = sub { warn __stamp(shift) }; $SIG{__DIE__} = sub { die __stamp(shift) }; # This sub Copyright (c) 1996,97,98,99,2000,01 by Randal L. Schwartz sub __stamp { my ($message) = @_; my $stamp = sprintf "[$$] [%02d@%02d:%02d:%02d] ", localtime[3,2,1,0 +]; $message =~ s/^/$stamp/gm; $message; }

After that, all your output to STDERR (warnings, dies) will be prefixed with the (time)stamp.

Replies are listed 'Best First'.
Re: Re: Formatting STDERR
by Abigail-II (Bishop) on Feb 12, 2004 at 10:09 UTC
    Not really. All your dies and warnings will be formatted (until someone localises $SIG{__WARN__} or $SIG {__DIE__}). It doesn't format anything generated with print STDERR.

    I suggest using IPC::Open3, with "-|" as the fourth argument. This will fork the process, allowing the parent to read STDERR from the child, and hence you are able to format STDERR they way you want.

    Abigail