Is it possible to log errors from different apache modules to separate log files?

Viewed 80

Is it possible to separate apache errors from different apache modules to different log files? For example rewrite module would log all errors from rewrite module to rewrite_error_log and all authz errors would log into authz_error_log and everything else would go to general error_log.

My particular use case:

I made a virtualhost configuration that has an unreachable path unless you come from certain ip (VPN gateway):

<Directory /var/www/my/app/path>
  # Allow Company gateway
  Require ip 1.2.3.4
</Directory>

# Logfiles
ErrorLog  /var/www/logs/app_error.log
CustomLog /var/www/logs/app_access.log combined

and it works as intended. Now consider that people hop out of the company VPN and their page requests are denied as intended. Authz_core will error log all these denied page requests with error messages like this:

[authz_core:error] [pid 12345] [client 111.222.1.2:12345] AH01630: client denied by server configuration: /var/www/my/app/path, referer: https://domainname.tld/

These messages will clog up the error_log and I would like to redirect all those 'not-important' error logs to a dedicated authz_error_log file. The ratio of authz errors to other errors is thousands to one.

What I've considered

  • I can turn off those particular authz errors with Loglevel authz:crit but I'd rather have them in a different log file if possible.
  • CustomLog can be used with SetEnvIf but I don't know how to set it up to catch modules
  • Using Piped Logs to somehow do the separation logic based on grepping the error message for module names which to be fair sounds quite awful idea
0 Answers
Related