Forum Moderators: coopster

Message Too Old, No Replies

PHP - Apache Access Log toggling

         

Lisa

6:30 pm on Sep 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Inside PHP I would like to exclude some requests from getting logged in the access log. How would I do this. I think I have to set an apache variable in PHP and then have my conf file in apache look for that variable to then toggle it.

Duckula

6:43 pm on Sep 21, 2002 (gmt 0)

10+ Year Member



As far as I know Apache doesn't allows selective logging; however, if you want to analize the logs omiting the ones that match an expression, it's possible to filter them with grep using the -v flag:

cat mylogfile ¦grep -v foo > filteredlog

will give you a logfile with the entries containing 'foo' trimmed out.

Personally, I don't think omiting valuable data on the logs would be good; but good luck finding out.

Lisa

6:57 pm on Sep 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From the research I have done, I am very sure it can be done. The trick is figuring what exactly I need to do.

inside my PHP


<?
apache_setenv("LOGOFF",1);
?>

Then inside the apache conf there would be an if statement.

inside my httpd.conf


if [ ]; then # Not sure on the exact if construct inside apache
error=yes
fi

Or maybe

inside my httpd.conf


CustomLog /usr/local/www/vhosts/website.com/logs/access_log COMBINED env=!LOGOFF
CustomLog /usr/local/www/vhosts/website.com/logs/ignore_log COMBINED env=LOGOFF

I am close I can feel it...

Duckula

9:03 am on Sep 22, 2002 (gmt 0)

10+ Year Member



Hey, what do you know, I found this at [httpd.apache.org...]

Conditional Logging

Environment variables can be logged in the access log using the LogFormat option %e. In addition, the decision on whether or not to log requests can be made based on the status of environment variables using the conditional form of the CustomLog directive. In combination with SetEnvIf this allows for flexible control of which requests are logged. For example, you can choose not to log requests for filenames ending in gif, or you can choose to only log requests from clients which are outside your subnet.

You would need a module to do that, I think.

<added>But you already knew, didn't you? :) </added>

[edited by: jatar_k at 12:54 am (utc) on Sep. 24, 2002]
[edit reason] trimmed trailing dot [/edit]

lorax

7:02 pm on Sep 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Lisa,
I believe what you're looking for can be found at:

[httpd.apache.org...]

Duckula

8:48 pm on Sep 23, 2002 (gmt 0)

10+ Year Member



WebmasterWorld software bited on my previous link... trim the trailing dot ;(

[httpd.apache.org...] will be helpful too :) Don't forget to tell us if this works, I had tried before but gave up.