4

I like to maintain separate Apache2 logfiles for each of my named virtual hosts, like this:

<VirtualHost *:80>
  ServerName myhost.example.com
  ErrorLog /var/log/apache2/myhost-error.log
</VirtualHost *:80>

The nominated file correctly gathers error-messages generated by Apache2 itself, such as 404s:

[Thu Jul 18 12:07:45 2013] [error] [client 10.0.0.141] File does not exist: /home/mike/myhost/htdocs/favicon.ico

But when myhost runs mod_perl scripts which emit their own logging messages (using print to STDERR, for example), those messages still appear in the global Apache2 error-log, /var/log/apache2/error.log.

This is using Apache 2.2.16 on Debian GNU/Linux 6.0, but I also see the same thing on Ubuntu 12.04.2 LTS and on MacOS 10.5 -- I guess it's standard Apache2 behaviour.

I want my mod_perl scripts' logging to appear in the site-specific error-log just like the 404s and other Apache-level errors. How can I make this happen?

1 Answers1

0

This is partially solved by overriding warn for your scripts. STDERR still goes to the main Apache error log though.

From Modperl docs:

  1. First, we need to use mod_perl's logging function, instead of CORE::warn

Either replace warn with Apache2::ServerRec::warn:

use Apache2::Log ();
Apache2::ServerRec::warn("the code is smoking");

or import it into your code:

use Apache2::ServerRec qw(warn); # override warn locally
warn "the code is smoking";
marcolz
  • 135
  • 7
  • 2
    Thanks, this is helpful. But it seems like the wrong solution to the problem. Surely _all_ stderr output should go to the nominated error-file? Or, if that is not the default (and it's not) there ought to be a simple option to make it so? – Mike Taylor Jul 06 '18 at 11:15