Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Multiplexing STDOUT and STDERR

by jmanning2k (Pilgrim)
on Nov 12, 2003 at 21:00 UTC ( [id://306633]=note: print w/replies, xml ) Need Help??


in reply to Re: Multiplexing STDOUT and STDERR
in thread Multiplexing STDOUT and STDERR

OK, I realize Log4Perl is a lot of work rewriting your scripts, but trust me, it's worth it. For a quick start, follow the easy_init directions, and just replace all your 'print "' with $log->info(), and all the warn or 'print STDERR' calls with $log->warn().

But, of course you would like to use as much of the existing script as possible. So, to address your current problem, try using \*STDOUT directly in the IO::Tee call. I've found odd behavior when I pass it as another variable, vs passing it as \*STDOUT and \*STDERR. Call multiplex with some sort of indicator instead of the reference (a string perhaps "STDOUT" or "STDERR"), and make separate calls to IO::Tee for each of these.

To debug this, try using the handles method of IO::Tee. Add a print join(' ', $tee->handles), "\n"; (taken from the perldocs) to your multiplex method to see what it's really producing. Compare the results of using the Handle reference, vs using \*STDOUT.

I know the above works, but making separate calls to IO::Tee is pretty ugly. This is untested, but you might try creating a new filehandle object pointing to STDOUT. Perhaps something like IO::File->new(\*STDOUT), or more basic, IO::Handle->new_from_fd(fileno(STDOUT),"w"). Pass the return value from one of these to multiplex instead of the reference to the glob.

~J

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://306633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found