http://www.perlmonks.org?node_id=897768

poulhs has asked for the wisdom of the Perl Monks concerning the following question:

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