Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Both print and redirect STDOUT and STDERR

by Perlbotics (Chancellor)
on Feb 09, 2012 at 21:01 UTC ( #952849=note: print w/replies, xml ) Need Help??

in reply to Both print and redirect STDOUT and STDERR

I need a solution which prints STDOUT and STDERR both to the screen and to a file at the same time.
So, here is one solution. Maybe it is too complicated, but your question smells like logging anyhow.

use strict; use Log::Log4perl qw(get_logger); # Define configuration for file test.log, STDERR, and STDOUT my $conf = q( log4perl.logger = ALL, FileApp, Screen +STDERR, ScreenSTDOUT log4perl.appender.FileApp = Log::Log4perl::Appen +der::File log4perl.appender.FileApp.filename = test.log log4perl.appender.FileApp.layout = PatternLayout log4perl.appender.FileApp.layout.ConversionPattern = %m%n log4perl.appender.ScreenSTDERR = Log::Log4perl::Appen +der::Screen log4perl.appender.ScreenSTDERR.stderr = 1 log4perl.appender.ScreenSTDERR.layout = PatternLayout log4perl.appender.FcreenSTDERR.layout.ConversionPattern = %m%n log4perl.appender.ScreenSTDOUT = Log::Log4perl::Appen +der::Screen log4perl.appender.ScreenSTDOUT.stderr = 0 log4perl.appender.ScreenSTDOUT.layout = PatternLayout log4perl.appender.ScreenSTDOUT.layout.ConversionPattern = %m%n ); # Initialize logging behaviour Log::Log4perl->init( \$conf ); # Obtain a logger instance my $logger = get_logger("Chess::GUI"); $logger->info("This is going to test.log, STDERR, and STDOUT.");

Log::Log4perl is quite powerful. You could try experimenting with different conversion patterns as explained in Log::Log4perl::Layout::PatternLayout.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952849]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-22 00:44 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.