Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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
share|improve this answer
    
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 Apr 6 '12 at 4:08
    
I have added an example for sub directories. Not tested, just an idea. –  toscho Apr 6 '12 at 4:16
    
Hmm, I see what you’re doing. I’ll try it out. –  Synetech Apr 6 '12 at 4:17
    
@Synetech Did it work? –  toscho Oct 6 '12 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 Oct 13 '12 at 18:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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