Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Both print and redirect STDOUT and STDERR by Perlbotics
in thread Both print and redirect STDOUT and STDERR by chessgui

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found