Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

stderr to script-logfile with CGI::Fast

by poulhs (Beadle)
on Apr 06, 2011 at 13:00 UTC ( #897768=perlquestion: print w/replies, xml ) Need Help??
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.


Replies are listed 'Best First'.
Re: stderr to script-logfile with CGI::Fast
by Anonymous Monk on Apr 06, 2011 at 13:06 UTC
    BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or die("Unable to open mycgi-log: $!\n"); carpout(LOG); }

      Thanks, but that did not do the trick, CGI::Fast->new() (actually FCGI), reopens the file-handle.

      anyone got an idea how to change this behavior?

Re: stderr to script-logfile with CGI::Fast
by poulhs (Beadle) on Apr 06, 2011 at 18:56 UTC

    The cause of the "problem"


    /* * Close STDIN unconditionally. It's used by the parent * process for CGI communication. The FastCGI applciation * will be replacing this with the FastCGI listenFd IF * STDIN_FILENO is the same as FCGI_LISTENSOCK_FILENO * (which it is on Unix). Regardless, STDIN, STDOUT, and * STDERR will be closed as the FastCGI process uses a * multiplexed socket in their place. */

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://897768]
Approved by Corion
Front-paged by Corion
[Discipulus]: I already know how much distinct paths exists but to demonstrate the property i want to have them all
[oiskuu]: ie C(n, k); where n is height difference, k is position in the line
[Discipulus]: infact there are 70 distinct path to reach the tale wich holds 70
[Discipulus]: what i want is to compute them
[oiskuu]: You want to draw the path? $iter = combinations( $TOP_HEIGHT .. $NODE_HEIGHT, $pos); then get the path from the iter, level change at depth x, for(..) $pos += $level_change; something like that
[oiskuu]: yergh, <code> tags... [$top_height .. $node_height]

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2018-03-19 11:09 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.