cancel
Showing results for 
Search instead for 
Did you mean: 

ccgi and weblogs, where does STDERR go?

oliverb
Grafter
Posts: 606
Registered: 02-08-2007

ccgi and weblogs, where does STDERR go?

I've been trying out some perl scripts and I know that they'll have written some trace info to STDERR. Supposedly anything a script writes to STDERR is supposed to get logged but this doesn't seem to be the case.
should I see warnings in the logfile or do Plusnet direct them to /dev/null? I can quite understand the latter, and can work around it by diverting the messages e.g. with CGI::Carp's fatalsToBrowser option but I'd like to know?
edit: Oops, I meant STDERR not STDOUT
5 REPLIES
Community Veteran
Posts: 14,469
Registered: 30-07-2007

Re: ccgi and weblogs, where does stdout go?

stdout and strerr sends output direct to the console (i.e. your telnet sesson) when you run them from the command line. When run from a browser they are probably ignored and not logged anywhere in a multi-host webserver environment.
You best bet is to find some way to redirect the output to a file.
Community Veteran
Posts: 1,264
Registered: 04-04-2007

Re: ccgi and weblogs, where does stdout go?

When running a script through the browser, STDOUT is sent to the browser. In perl for example, [tt]print 'Test'[/tt] is sent to STDOUT and will display in the browser.
oliverb
Grafter
Posts: 606
Registered: 02-08-2007

Re: ccgi and weblogs, where does stdout go?

I've got it mixed up again, I meant STDERR. I've learned the hard way where STDOUT goes as anything at all written before the HTTP header breaks it totally.
As far as I know "warn","carp","die" and "croak" (and "cluck" and "confess") all send their output to STDERR by default. Adding CGI::Carp makes it format the message nicely with a date and time in front on the assumption that Apache will capture STDERR into the logfile.
Plan B as Peter points out is to redirect the output to a seperate logfile on the cgi server. Easier said than done when the example given by cpan throws an error when run with "use strict" selected.
Oh well I've now got it to work and made the script carry on quietly without logging if the logfile can't be opened instead of throwing a 500 error.
Community Gaffer
Community Gaffer
Posts: 5,111
Thanks: 443
Fixes: 5
Registered: 04-04-2007

Re: ccgi and weblogs, where does STDERR go?

oliverb: http://www.issociate.de/board/post/261491/Redirecting_STDERR.html
Kelly Dorset
Broadband Service Manager
oliverb
Grafter
Posts: 606
Registered: 02-08-2007

Re: ccgi and weblogs, where does STDERR go?

Thankfully with CGI::Carp there's the "carpout" function, so I can dodge having to save and restore the filehandle myself.
BEGIN 
{
  use CGI::Carp qw(carpout);
  open(LOG, ">>log/mycgi-log.txt") and
  carpout(*LOG);
}

This is based on the example in the docs except that I've replaced the "do or die" file open with "open and do stuff" so it doesn't bomb if the file can't be opened, also the star in front of LOG prevents a bareword error.