Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am writing an application that uses a large number of custom scripts and CPAN modules together. As part of the requirements for the project, I need to be able to log all the output from the program, both STDOUT and STDERR.

I am using this module that I have written:

package Tie::Annotate; use base qw(Tie::FileHandle::Base); use IO::File; use strict; use warnings; sub TIEHANDLE { my $class = shift; my $annotation = shift; my $handle = new IO::File ">> test.err" or die "Cannot open file: +$!\n"; #$self->{FH} = *$FH; return bless {FH => $handle, ann => $annotation}, $class; } sub PRINT { my $self = shift; my $string = shift; my $handle = $self->{FH}; print $handle "$self->{ann} " . $string; } 1;
And early in the program I declare:
tie *STDOUT, "Tie::Annotate", 'OUT'; tie *STDERR, "Tie::Annotate", 'ERR';

And this generally works correctly, outputting to STDOUT gets appended to the error log with OUT at the start of the line and STDERR gets appended to the error log with ERR and the start of the line.

But there is a problem; one of the CPAN modules (Cvs) relies on IPC::Run which dies when STDERR and STDOUT are captured like this.

FWIW the actual error message is

 Can't call method "slave" on an undefined value at /home/FCS/teh/perl/lib/perl5/site_perl/5.8.5/IPC/Run.pm line 2816

IPC::Run's verion is $VERSION = " 0.80";

Is there something crazy with what im trying to do?

A suggestion of a better way to catch STDOUT and STDERR would be appreciated if there is any... Unfortunatly, Log4Perl is not an option.


In reply to How to log all output from a program? by absolut.todd

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 having a coffee break in the Monastery: (5)
As of 2024-03-28 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found