Seeking the wisdom of the monks...

I am trying to redirect stderr to a script-specific logfile from a CGI::Fast script:

#!/usr/bin/perl use strict; use warnings; use English qw( no_match_vars ); use Fcntl; use CGI::Fast; our $errlog; BEGIN { $errlog = "/var/tmp/foo.log"; sysopen( STDERR, $errlog, O_WRONLY | O_CREAT | O_APPEND ) or warn( "Failed to open $errlog: $ERRNO" ); } warn( "OK\n" ); while (my $q = CGI::Fast->new()) { print $q->header(), $q->start_html( sprintf( "%2.2d:%2.2d:%2.2d", ( localtime($^T) ) +[2,1,0] ) ), $q->h1( scalar localtime( $^T ) ), $q->code( "pid=$$ errlog=$errlog" ), $q->end_html,"\n"; warn( "NOT OK\n" ); } __END__

The "problem" seems to be, that CGI::Fast->new() (which is calling FCGI::accept()), resets STDERR. I've even tried misc. stuff after the CGI::Fast->new(), like reopening sysopen( STDERR, $errlog, ... ) and more obfuscating stuff like my $req = $FCGI::global_request; followed by misc. dup'ing and/or *STDERR = ...

Anyone got a solution to this problem (or tinks it is unsolvable)?

ps: I have no problems with $SIG{__WARN__} and $SIG{__DIE__} handlers, but would really like to redirect STDERR completely.

amen


In reply to stderr to script-logfile with CGI::Fast by poulhs

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.