You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Wojciech Pietron <W....@itl.waw.pl> on 2003/08/27 09:55:41 UTC

Carpout in mod_perl

Solaris 2.5.1
perl 5.6.0
Apache/1.3.27 (Unix) mod_perl/1.27
CGI 2.76
CGI::Carp 1.20 

Hi,

I have problems with redirecting STDERR in mod_perl. Have a look at the
following example:

======================================================
#/usr/bin/perl -w

use CGI qw(header param url_param url);
use CGI::Carp qw(fatalsToBrowser croak carp carpout);

my ($pwd, $errorlog, $fh);

BEGIN {
   $pwd = qx|/bin/pwd|;
   chop $pwd;
   $errorlog = "$pwd/myerror.log";
   $fh = new FileHandle ">> $errorlog";
   carpout($fh);
}

# functions printing to STDERR 
...
======================================================

If I use CGI instead of mod_perl, it is OK. I have all my STDERR messages at
myerror.log.  But when I put my script in mod_perl environment then I have some
of the messages in myerror.log and some in standard Apache error_log file.  If
I run my script a few times, I can see that the message appears randomly either 
in myerror.log or in error_log file.

I am not able to determine when messages are going to myerror.log and when they
are going to error_log. Is it a feature of mod_perl? 

Thank you in advance for your help.
Best regards,
Wojciech Pietron


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Carpout in mod_perl

Posted by Josh Chamas <jo...@chamas.com>.
Wojciech Pietron wrote:
>...
> use CGI qw(header param url_param url);
> use CGI::Carp qw(fatalsToBrowser croak carp carpout);
> 
> my ($pwd, $errorlog, $fh);
> 
> BEGIN {
>    $pwd = qx|/bin/pwd|;
>    chop $pwd;
>    $errorlog = "$pwd/myerror.log";
>    $fh = new FileHandle ">> $errorlog";
>    carpout($fh);
> }
> 
> # functions printing to STDERR 
> ...
> ======================================================
> 
> If I use CGI instead of mod_perl, it is OK. I have all my STDERR messages at
> myerror.log.  But when I put my script in mod_perl environment then I have some
> of the messages in myerror.log and some in standard Apache error_log file.  If
> I run my script a few times, I can see that the message appears randomly either 
> in myerror.log or in error_log file.
> 
> I am not able to determine when messages are going to myerror.log and when they
> are going to error_log. Is it a feature of mod_perl? 
> 

In mod_perl, you should be aware that BEGIN {} blocks only get executed the
first time a script is compiled, so is not a reliable place to execute code
that you want executed once per script.  If you reall want the code execute
each request, put it into a subroutine, and call that routine each time.

Regards,

Josh

________________________________________________________________
Josh Chamas, Founder                   phone:925-552-0128
Chamas Enterprises Inc.                http://www.chamas.com
NodeWorks Link Checker                 http://www.nodeworks.com



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html