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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.