Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't log certain requests in Apache access.log

Tags:

apache

matomo

I recently replaced Google Analytics by the self-hosted analytics tool Piwik.

This means that every time someone connects my website http://www.mywebsite.com, a Javascript tracking code is executed on the client, that calls my Piwik server http://www.mywebsite.com/piwik/piwik.php

Result:

  1. on my server's Apache access.log, there is a line about http://www.mywebsite.com, that's normal
  2. in my Piwik database, an information is stored about this visit, this is normal
  3. on my server's Apache access.log, there is a line about the fact my Piwik server received a tracking request (executed by client with JS)

The logging part 3. is clearly too much! From now, since Piwik in installed, my access.log is double sized!

How to remove the fact that Apache logs in access.log the connection to http://www.mywebsite.com/piwik/piwik.php ? i.e. client JS tracking code <--> Piwik server ?

like image 713
Basj Avatar asked Dec 14 '22 03:12

Basj


1 Answers

The solution is to disable logging of certain requests (for example in /etc/apache2/sites-available/000-default.conf with Debian 8):

<VirtualHost *:80>
  ServerName www.mywebsite.com
  DocumentRoot /home/www/mywebsite
  ...
  SetEnvIf Request_URI "^/piwik(.*)$" dontlog
  CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined env=!dontlog
</VirtualHost>
like image 56
Basj Avatar answered Jan 05 '23 01:01

Basj