0

I have a server that runs on apache. To track users' access to specific objects I'm trying to modify the server logs and keep them formatted so that I can have a brief analysis with them. But unfortunately, I can not configure the log files properly. I want to keep only those logs which are giving me status code of 200. I've written some configs but they are saving 404 logs and just ignoring the 200 status code logs. Here is my virtual host configuration.

    SetEnvIfNoCase Request_URI "\.(gif)|(jpg)|(png)|(css)|(js)|(ico)|(eot)\HTTP\304$" dontlog
    CustomLog /var/log/httpd/access.json common

Response

host_ip - - [06/Dec/2020:17:25:17 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:25:18 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:25:20 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:25:49 +0000] "GET /single/5e2fc23ad8759046d872e1bb HTTP/1.1" 404 196
host_ip - - [06/Dec/2020:17:25:50 +0000] "GET /single/5e2fc23ad8759046d872e1bb HTTP/1.1" 404 196
host_ip - - [06/Dec/2020:17:26:28 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:27:23 +0000] "GET /single/5d63a416f1245ab97a262fc2 HTTP/1.1" 404 196
host_ip - - [06/Dec/2020:17:28:06 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:28:08 +0000] "GET / HTTP/1.1" 304 -
host_ip - - [06/Dec/2020:17:28:22 +0000] "GET / HTTP/1.1" 304 -

These file is saving all the logs but except the 200 status code logs. I have created another one that is tracking the 200 but can not write them on file.

#conf for 200 
    SetEnvIf status_code = 200 STATUS_OK
    CustomLog /var/log/httpd/ok.log "%t %a,%{User-Agent}i %U%q %s" env=STATUS_OK

response

- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -
- -,- -- -

Here the 200 is getting here but my apache can not create the log files or it just couldn't understand that it is a 200. Could anyone help me with this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.