Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Both print and redirect STDOUT and STDERR

by Perlbotics (Abbot)
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.


Comment on Re: Both print and redirect STDOUT and STDERR
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-02 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls