Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache2 Logging Conditional with multiple env set

So we have X-Forwarded-For enabled on our SLBs which is working, and I've got correct logging working via the link here, which says to use this SetEnvIF statement.

The problem we are running into is, the SLBs also check ever 5seconds via a GET /health.html file, which is filling up our logs. I was able to find a way to get apache2 to stop logging specific files, however I cannot seem to find a way to do both X-Forward-For and Don't Log specific files.

This was my last attempt, when I read a blog saying you could use multiple Env and sepearate them by a ',' which didn't owrk :(.

    #logs
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
    SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
    SetEnvIf Request_URI "^/health\.html$" dontlog

    CustomLog "/www/logs/access.log"  combined env=!forwarded,!dontlog
    CustomLog "/www/logs/access.log"  proxy env=forwarded

I appreciate everyones help.

Thank you for your time.

like image 542
Jim Avatar asked Nov 27 '22 05:11

Jim


1 Answers

For your case it should be:

CustomLog       /www/logs/access.log combined expr=(reqenv('forwarded')=='no'&&reqenv('dontlog')=='no')
CustomLog       /www/logs/access.log proxy expr=(reqenv('forwarded')=='yes')

The last one can be an env but I left as a expr for a 'yes' example.

like image 88
Rudiger Avatar answered Dec 05 '22 12:12

Rudiger