14

I'm trying to use Apache's CustomLog directive to create some custom log files, but can't get it working. Here is the configuration I'm using for the custom logs:

LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

CustomLog /var/log/apache2/jb_common common
CustomLog /var/log/apache2/jb_referer referer

Apache creates both of these custom log files on startup, so it definitely sees the CustomLog directives, but it never writes anything to these files; however, the default access log (access.log) is being written to.

Any ideas? I'm running Apache 2.2 on Ubuntu 8.10.

Mike Spross
  • 7,999
  • 6
  • 49
  • 75

2 Answers2

14

I have the same problem with Ubuntu 9.10 Server and Apache 2.2.12. I'm setting up a Subversion server with mod_dav_svn and added a CustomLog directive to /etc/apache2/mods-available/dav_svn.conf to log Subversion requests, but had the same problem (the log file was created when Apache started, but was never written to):

<Location /svn>
  ...
</Location>

LogFormat "%t %u %{SVN-ACTION}e" svn_log
CustomLog /var/log/apache2/svn_access.log svn_log env=SVN-ACTION

There are two workarounds for the issue that I found, which basically amount to the same thing. I'm documenting both here because they have different pros and cons.

Workaround 1

  1. Delete the CustomLog directive from your configuration file, if you have it set up in a separate configuration file.

  2. Add the CustomLog directive to your site's VirtualHost entry. For me this was in /etc/apache2/sites-available/default-ssl because I'm only allowing SSL access to the Subversion repository. If you are using /etc/apache2/sites-available/default, you will want to edit that file instead (or in addition to default-ssl if you are using both).

  3. Restart Apache:

sudo /etc/init.d/apache2 restart

Pro

You can have multiple CustomLog directives in the VirtualHost entry for your site, and they will all work.

Con

You have to move your CustomLog entry into your site's VirtualHost entry instead of having it in a separate configuration file.

Workaround 2

  1. Comment out the CustomLog directive(s) in your site's VirtualHost entry. If you're using one of the default site configurations (default or default-ssl), there will be a CustomLog directive for the access log that you will need to comment out (yes, this turns off Apache's default access logging).

  2. Add your CustomLog directive to the appropriate configuration file. For me this was /etc/apache2/mods-available/dav_svn.conf.

  3. Restart Apache:

sudo /etc/init.d/apache2 restart

Pro

You can keep your CustomLog directive in a separate configuration file.

Con

This workaround has the obvious disadvantage that you have to disable Apache's default access logging, but for me I don't care that much since I'm only using the server for Subversion access.

Conclusion

Neither of these workarounds are really ideal, but so far I haven't found a way to get it to work other than than the two workarounds above. I suppose we'll have to wait for the next release of Apache for this issue to be fixed.

Mike Spross
  • 7,999
  • 6
  • 49
  • 75
  • Your Workaround 1 worked for me too. RHEL 5.9, Subversion 1.6, Apache 2.2. Thanks! – sierrasdetandil Jun 11 '13 at 17:18
  • 1
    Note that this is exactly per apache docs, http://httpd.apache.org/docs/2.2/logs.html#virtualhost "If CustomLog or ErrorLog directives are placed inside a section, all requests or errors for that virtual host will be logged only to the specified file. Any virtual host which does not have logging directives will still have its requests sent to the main server logs." – Eddie Oct 18 '13 at 13:43
  • When you said *"... the appropriate configuration file. For me this was `/etc/apache2/mods-available/dav_svn.conf`"*, I hope you were meaning `sites-available` (or `conf.d`, or even the modern `confs-available`), **not** `mods-available` – MestreLion Feb 04 '16 at 04:41
  • Since Apache 2.4.19 there is a [GlobalLog](http://httpd.apache.org/docs/current/mod/mod_log_config.html#globallog) directive: "GlobalLog is used by virtual hosts that define their own CustomLog, unlike a globally specified CustomLog." – xebeche Feb 10 '17 at 23:25
0

One problem you might be running into, is if you redirect http request to https via a rewrite rule, you might have two different configuration files for the same VirtualHost, one serving *:80 and another serving *:443

So maybe check that you didn't write your CustomLog directive only in the VirtualHost config file serving http!

(yes, it did happen to me)