3

A while back I left Blogger and downloaded my blogs to my system. I hosted them there with each individual blog as a VirtualHost for a while. Later, I imported them into WordPress and am hosting them from WP now.

When I was hosting them locally as virtual hosts, I had each one use a separate Apache log file, but now, all of the blogs are logged to the same file.

I cannot find a setting in WordPress, and there is no way to specify it in an .htaccess file since the sites are virtual. That is, WordPress blogs are not actually located on the drive as separate directories—(besides, log settings cannot be used in .htaccess anyway).

How can a WordPress multi installation be configured so that one or more sites log to their own log file?

toscho’s second suggestion of using SetEnvIf is promising. I managed to get it to put access to one site in a separate log file and keep it out of the main log by using the directives below.

…
<IfModule log_config_module>
  …
  # I’m re-using the dontlog environment variable because there is no reason to make a special variable (for me), so it avoids having to use an expression (plus, it just makes sense)
  SetEnvIf Request_URI "^/blogs"        dontlog
  SetEnvIf Request_URI "^/blogs/blog1"  blog1
  SetEnvIf Request_URI "^/blogs/foobar" foobar
  …
  CustomLog "../Logs/Main/access.log"  common env=!dontlog
  CustomLog "../Logs/Blogs/blog1.log"  common env=blog1
  CustomLog "../Logs/Blogs/foobar.log" common env=foobar
  …
  UnsetEnv  dontlog
  UnsetEnv  blog1
  UnsetEnv  foobar
</IfModule>
…

This works for a single-site blog, but for multisite, the problem is in trying to keep things uncluttered and simplify adding new blogs because it looks like it is not possible to use variables in log filenames as follows, which means making a separate entry for each and every one:

…
<IfModule log_config_module>
  …
  SetEnvIf Request_URI "^/blogs"         dontlog
  # Set environment variable to matched regex subexpression corresponding to blog name
  SetEnvIf Request_URI "^/blogs(.+/)"    blog=$1
  …
  CustomLog "../Logs/Main/access.log"    common env=!dontlog
  CustomLog "../Logs/Blogs/%{blog}e.log" common env=blog
  …
  UnsetEnv  dontlog
  UnsetEnv  blog
</IfModule>
…

I end up with a log containing all blog access in a file named %{blog}e.log.

1 Answer 1

1

You could set up custom logs in your httpd-vhosts.conf depending on the HTTP_HOST variable – if your server is an Apache and you use subdomains for each single site.

For sub directories (not tested):

SetEnvIf Request_URI ^sitename1 sitename1
SetEnvIf Request_URI ^sitename2 sitename2
CustomLog sitename1.log common env=sitename1
CustomLog sitename2.log common env=sitename2
5
  • Like I said, that’s what I did before moving to WordPress. That won’t work now because the sites in wpmu are don’t exist in folders on disk or as virtual hosts in Apache: blah.com/blogs/foo, blah.com/blogs/bar.
    – Synetech
    Commented Apr 6, 2012 at 4:08
  • I have added an example for sub directories. Not tested, just an idea.
    – fuxia
    Commented Apr 6, 2012 at 4:16
  • Hmm, I see what you’re doing. I’ll try it out.
    – Synetech
    Commented Apr 6, 2012 at 4:17
  • @Synetech Did it work?
    – fuxia
    Commented Oct 6, 2012 at 22:17
  • No, it didn’t; the logs were empty. I’m testing to see if using the <If> directive can help, but it requires upgrading to 2.3+.
    – Synetech
    Commented Oct 13, 2012 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.