1

I would like to separate apache 2.2 log entries in 2 log files: requests from LAN (192.168.0.0/16) should go in a lan-access.log, and the rest in the default access.log

How can I achieve that? I've tried to use SetEnvIf and conditional logging as described in https://httpd.apache.org/docs/current/logs.html#conditional :

$ cat /etc/apache2/conf.d/lan-access-log.conf 
SetEnvIf Remote_Addr "192\.168\." fromlan
CustomLog ${APACHE_LOG_DIR}/lan-access.log common env=fromlan

but it doesn't work and LAN requests keep popping up in the main acess.log. What is wrong with my config?

mp04
  • 187
  • 8
  • See also [Disabling Apache logging of particular requests](http://www.debian-administration.org/article/707/Disabling_Apache_logging_of_particular_requests) – mp04 Aug 07 '14 at 11:20

1 Answers1

2

You forget to configure the inverse , besides writing your LAN requests to it's own log you need to exclude them from the regular log as well...

 # Where your access log is defined
 CustomLog logs/access_log common env=!fromlan

Make sure that the SetEnvIf line is declared before the regular access log is.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • Right, added this to `lan-access-log.conf` and it works. I also had to remove the `CustomLog` directive from the virtualhost in `sites-available` or it would override the config. – mp04 Jul 05 '14 at 14:15