logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.


Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Reduce entries in my AccessLog based on status code
Author
dominic01



Joined: 26 Aug 2014
Posts: 5
Location: India, Chennai

PostPosted: Tue 26 Aug '14 12:28    Post subject: Reduce entries in my AccessLog based on status code Reply with quote

Basically I would like to record only certain status code entries in my access log. For example I would like to skip all entries with 200 status.

The documentation under "Modifiers" http://httpd.apache.org/docs/current/mod/mod_log_config.html works somewhat but it still makes an entry in the AccessLog file.

This line in httpd.conf
Quote:
LogFormat "%h %l %u %t \"%r\" %>s \"%!200,304{Referer}i\"" common

changes the Referer to "-" but the following two lines are not working

Quote:
SetEnvIf Referer "^-$" DontLog
CustomLog "logs/access.log" common Env=!DontLog


Appreciate any help in this regards
Dominic
Back to top
AdrianK_IT



Joined: 30 May 2013
Posts: 34
Location: Scottish Borders, UK

PostPosted: Tue 26 Aug '14 14:46    Post subject: Reply with quote

Sorry if this seems a silly question, but you have loaded setenvif_module?
Back to top
dominic01



Joined: 26 Aug 2014
Posts: 5
Location: India, Chennai

PostPosted: Wed 27 Aug '14 10:36    Post subject: Reply with quote

Yes. I have loaded that module. I tested by skipping all the "gif" files and it works fine.
Back to top
AdrianK_IT



Joined: 30 May 2013
Posts: 34
Location: Scottish Borders, UK

PostPosted: Wed 27 Aug '14 10:49    Post subject: Reply with quote

Given this more thought, and I realise you need to use a construction like:

Code:
CustomLog "logs/access.log" common expr=%{REQUEST_STATUS}!='200'


in your httpd.conf

Using the %!200 etc construction in your LogFormat does not change Referer to '-', it simply doesn't log it ie you can't SetEnvIf based on it. The '-' is just a placeholder, to show nothing has been logged there, it is not what the value of Referer now is.

Edit: I guess the full line you need is:

Code:
CustomLog "logs/access.log" common expr=%{REQUEST_STATUS}!='200'&&%{REQUEST_STATUS}!='304'
Back to top
dominic01



Joined: 26 Aug 2014
Posts: 5
Location: India, Chennai

PostPosted: Wed 27 Aug '14 11:30    Post subject: Reply with quote

Code:
CustomLog "logs/access.log" common expr=%{REQUEST_STATUS}!='200'&&%{REQUEST_STATUS}!='304'

I am getting a syntax error for the above line
Code:
error in condition clause


Regards
Dominic
Back to top
AdrianK_IT



Joined: 30 May 2013
Posts: 34
Location: Scottish Borders, UK

PostPosted: Wed 27 Aug '14 11:35    Post subject: Reply with quote

All on one line, no spaces in expr= etc?
Back to top
dominic01



Joined: 26 Aug 2014
Posts: 5
Location: India, Chennai

PostPosted: Wed 27 Aug '14 11:44    Post subject: Reply with quote

Yes, All in one line and without spaces. Also I tried this
Code:
CustomLog "logs/access.log" common "expr=%{REQUEST_STATUS}!=200"
and got the same syntax error
Back to top
AdrianK_IT



Joined: 30 May 2013
Posts: 34
Location: Scottish Borders, UK

PostPosted: Wed 27 Aug '14 12:05    Post subject: Reply with quote

Sorry, dominic01, I'm stumped; I've tested the configuration on my server, and it works fine. What happens if you just use:

Code:
CustomLog "logs/access.log" common expr=%{REQUEST_STATUS}!='200'


Do you get a syntax error?

I'm pretty sure you must use '200' (it's a string, not a number) and not use ".." round the expr statement.

I do most of my log filtering after the event, using a PHP script (other languages are available!) to remove unwanted lines before opening it for analysis, so I'm no expert on expr. Perhaps someone else can help.
Back to top
dominic01



Joined: 26 Aug 2014
Posts: 5
Location: India, Chennai

PostPosted: Wed 27 Aug '14 12:24    Post subject: Reply with quote

The issue is with my Apache version. I was checking your suggestion in 2.2.22 and I just checked the syntax in 2.4.10 and it is fine. Now I need to get it installed in my local system and test the logging.

Edit: Thank you. Its Working in 2.4.10.
Back to top
AdrianK_IT



Joined: 30 May 2013
Posts: 34
Location: Scottish Borders, UK

PostPosted: Wed 27 Aug '14 12:39    Post subject: Reply with quote

Good-oh! I'm on 2.4.9 (mental note: always do as advised ie check versions before offering config advice!)
Back to top


Reply to topic   Topic: Reduce entries in my AccessLog based on status code View previous topic :: View next topic
Post new topic   Forum Index -> Apache