You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Christopher L. Everett" <ce...@ceverett.com> on 2003/04/25 02:04:46 UTC

"print STDERR 'foo';" only prints to the main server log

How can I use STDERR to print to the error log defined for a
name virtual server?  I'm needing to debug modulee that really
have nothing to do with Apache, and needing to watch two logs
at the same time chews up real estate on the screen.

I could tie STDERR to a filehandle at the beginning of the
request, but I'm not clear where I would get the filehandle
to tie to.


-- 
Christopher L. Everett
Chief Technology Officer
The Medical Banner Exchange
Physicians Employment on the Internet


Re: "print STDERR 'foo';" only prints to the main server log

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Christopher L. Everett wrote:
> Geoffrey Young wrote:
> 
>>
>>
>> Christopher L. Everett wrote:
>>
>>> How can I use STDERR to print to the error log defined for a
>>> name virtual server?  
>>
>>
>>
>> instead of printing to STDERR why not just use Apache::Log;
>>
>> $r->log->debug('whoa!');
>>
>> that should pick up your vhost specific ErrorLog settings.
>>
> 
> 
> Only works if you have an Apache object lying around.  

which you always do if you're running under mod_perl

Apache->request->log->debug('foo');

> I'd have to pass
> that in to method calls of objects/classes that have nought to do with
> Apache itself.

well you're just debugging and the above is pretty simple.

> 
> It would be so nice just to use print STDERR, or warn, and have error
> messages automagically end up where they belong.  Less to think about
> that way.

this is much harder than you think - we have an example of diverting 
the error log in chapter 16 of the mod_perl Developer's Cookbook that 
may be worth checking out.

> 
> Perhaps I should subclass Apache::Request, and override the print()
> method to divert its parameters to log_error if STDERR is the first
> parameter.

we have an example of doing that kind of stuff to print() in Chapter 
15, but if you have an object to tie then you have an object to just 
make log_error calls to :)

--Geoff


Re: "print STDERR 'foo';" only prints to the main server log

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Christopher L. Everett wrote:
> How can I use STDERR to print to the error log defined for a
> name virtual server?  

instead of printing to STDERR why not just use Apache::Log;

$r->log->debug('whoa!');

that should pick up your vhost specific ErrorLog settings.

HTH

--Geoff




Re: "print STDERR 'foo';" only prints to the main server log

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,

On Thu, 24 Apr 2003, Christopher L. Everett wrote:

> I could tie STDERR to a filehandle at the beginning of the
> request, but I'm not clear where I would get the filehandle
> to tie to.

There's no need to confuse things, you'll be debugging your debugging.
TMTOWTDI.  You could make it, with open(), and print everything to that.
Or you could print your messages to the browser.

Have you read the debugging secion of the Guide?

73,
Ged.