2

I want to get rid of superfluous logging in Apache. I've find tutorial how to use setenvif module for that purpose, setting variable dontlog.

The only problem is, I don't see on the criteria list what is the most interesting for me, the http status.

I'd like to do the following:

SetEnvIf Http_Status 200 dontlog

But it seems, there's no Http_Status support for SetEnvIf...

How to filter logs based on http status?

  • The `setenvif` module simple does not have an option to match the status code. You will have to look at other modules. – Tommiie Mar 12 '19 at 10:11

2 Answers2

5

A little bit of googling showed me the following result:

Per status code differentiation We all like HTTP status 200. It means 'OK' and that's why we're not interested in loging it. Most common situation is when we are looking for some specific status code in the logs. With mod_log_config you may create separate logs for every needed status. Please look at this configuration:

CustomLog ok.log "%200t %200a,%200{User-Agent}i %200U%200q %200s"
CustomLog redirections.log "%301t %301a,%301{User-Agent}i %301U%301q %301s"
CustomLog not_found.log "%404t %404a,%404{User-Agent}i %404U%404q %404s"
CustomLog server_error.log "%500t %500a,%500{User-Agent}i %500U%500q %500s"

It contains a link to this website.

Edit:

The (current) documentation of mod_log_config shows options for matching status codes:

Particular items can be restricted to print only for responses with specific HTTP status codes by placing a comma-separated list of status codes immediately following the "%". The status code list may be preceded by a "!" to indicate negation.

So I suggest you read through that page and configure CustomLog configurations that suit your needs. I would start with trying something like:

CustomLog /dev/null "%200"

Though the file name must be relative to the ServerRoot so some trickery will be required there. Perhaps check some chroot documentation on how to copy the file /dev/null to inside your ServerRoot.

Tommiie
  • 5,627
  • 2
  • 12
  • 46
1

This expression, worked for me: (Apache v2.4.52)

CustomLog /var/log/not_200.log vhost_combined "expr=%{REQUEST_STATUS} != 200"
Bruno Yuzo
  • 111
  • 3