[mp2] STDERR on a per-vhost basis?

[mp2] STDERR on a per-vhost basis?

am 11.03.2009 19:20:47 von Robert Buels

Hello all,

Under mod_perl 2, stderr for all virtual hosts seems to be opened to the
global Apache 2 error log (/var/log/apache2/error.log or similar). How
do I get stderr output to go to the ErrorLog that is defined for each
virtual host?


====EXTENDED CONTEXT====
Our organization maintains several mod_perl sites, each of which runs as
its own virtual host. They are currently implemented as CGI scripts
running under Apache 1.3, mod_perl 1, with Apache::Registry.

I am porting them from mod_perl 1/Apache 1.3/Apache::Registry to
mod_perl 2/Apache2/ModPerl::Registry. Under the old setup, stderr from
scripts in each vhost used to go into that vhost's error log, but now
that I have them running under the new setup, their stderr is going to
the global apache log. I want the stderr for each vhost to go to its
own error log.

Thanks in advance.

Rob

--
Robert Buels
Bioinformatics Analyst, Sol Genomics Network
Boyce Thompson Institute for Plant Research
Tower Rd
Ithaca, NY 14853
Tel: 503-889-8539
rmb32@cornell.edu
http://www.sgn.cornell.edu

Re: [mp2] STDERR on a per-vhost basis?

am 11.03.2009 19:47:36 von Clinton Gormley

Hiya

> Under mod_perl 2, stderr for all virtual hosts seems to be opened to the
> global Apache 2 error log (/var/log/apache2/error.log or similar). How
> do I get stderr output to go to the ErrorLog that is defined for each
> virtual host?

I was going to say that this is detailed here:
http://perl.apache.org/docs/2.0/api/Apache2/Log.html#Virtual _Hosts

but then I realised that this refers to redirecting warn() and warnings
to the virtual server error log, and that STDERR still goes to the main
error log.

You can reopen STDERR to the log file of your choice, as per:

open (*STDERR,'>',$log_file_path) or die $!

The question is when :)

Doing it in a PerlOpenLogsHandler is too soon, as this is only called
once, and not on a per-virtualhost basis.

By the time you're in a PerlRequestHandler, you don't (or shouldn't)
have permission to access the standard logs/ directory.

That said, I think it's your only real option, and I'd localise STDERR
before redirecting it, otherwise it'll probably affect other virtual
hosts which don't redirect.

hth

clint