2

I have several vhosts served by Apache 2.2.22 on a Debian Wheezy server. Some vhosts are Catalyst apps; all vhosts run with mod_fastcgi and mod_suexec. Each virtual host is configured to use a different ErrorLog.

When code in the Catalyst apps writes to stderr (e.g. warn is called), the message ends up in the main Apache error log instead of the one specified in the <VirtualHost> block. It's not prefixed by a timestamp or any other information.

However, if I call this trivial fastcgi script

#!/usr/bin/perl

use FCGI;

my $request = FCGI::Request();

while($request->Accept() >= 0) {
    print("Content-type: text/html\r\n\r\n");
    warn 'Hello!';
}

the Hello! does end up in the right place, correctly prefixed:

[Thu Jul 10 14:40:18 2014] [error] [client x.x.x.x] FastCGI: server "/data/vhost/wibble/docs/test.cgi" stderr: Hello! at test.cgi line 9., referer: http://my.test.site/

How can I get the Catalyst sites to write their stderr to the correct log?

The only related question I can find is this one -- similar problem but different module (mod_perl), and sadly no answers. I also found this Apache bug report, which describes the same problem with mod_cgid.

Edit: If I put

open STDERR, ">>../../applogs/app.log" or die "can't open applog: $!";

before the Catalyst loop, this redirects stderr to my log file, but obviously no datestamps or other prefixes are added. What I want is for stderr to be treated the same as for a bare FCGI script.

Flup
  • 7,978
  • 2
  • 32
  • 43

1 Answers1

1

I'm not sure why the ErrorLog directives in your virtualhost configurations aren't working, but the prefixing of text sent to STDERR is not done by apache. Rather the FCGI module does this by installing a warn handler.

Consider the documentation at http://search.cpan.org/~skimo/FCGI-0.67/FCGI.PL for $req->Accept(), which says

Note that unlike with the old interface, no die and warn handlers are installed by default. This means that if you are not running an sfio enabled perl, any warn or die message will not end up in the server's log by default. It is advised you set up die and warn handlers yourself. FCGI.pm contains an example of die and warn handlers.

If the warn handler implemented by your version of FCGI is directing your output to the right place, then it might be instructive to look at the code that implements that.

chicks
  • 3,793
  • 10
  • 27
  • 36
mc0e
  • 5,866
  • 18
  • 31