0

I'm not sure my question is clear, but here is a small explication:

I'm using apache mod_vhost_alias, which is great for me to create new domain easily (just create the according domain name folder) It is configured as is :

UseCanonicalName Off
VirtualDocumentRoot /var/www/%0/htdocs 

However, I'd like to be able to automatically write log to /var/www/%0/logs

Is there any way to do this with such mod?

Thank you

1 Answer 1

1

As far as I can tell you can't do this out of the box. But you can log to a named pipe or directly to a script and have the script recreate the logfiles as you wish:

http://httpd.apache.org/docs/current/logs.html#piped

If you need help with the script please post an example of your logfiles.

A non-optimized non-tested example written in shell script:

#!/bin/bash
# This assumes the host is mentioned in the first column, replace $1 with the right column if needed.
while read line
  do 
  virtualhost=`echo $line | awk '{print $1}'`
  echo $line >> /var/www/$virtualhost/log/access_log
done
7
  • Hi, thank you for pointing me this option, I tried to do CustomLog "|/home/user/testlog" combined It is called correctly, but it seems that it doesn't provide any arguments to the script, how could I retrieve the options to work with? Currently my script is just as follow: $options = print_r($argv, true); file_puts_content($file); (php code)
    – JohnT
    May 6, 2011 at 11:22
  • You can add any arguments inside the quotes, for example: "|/home/user/testlog arg1 arg2 ...". I think you're missing a parameter to file_puts_contents - also I don't think you should use that function in the final implementation, as it opens and closes the destination file each time. This is probably not what you want when logging. May 6, 2011 at 11:31
  • Hi, I'll think about logging optimization after, well my file_puts_content is correctly signed (not complete indeed in my comments) but works if I can it manually with /home/user/testlog something else foo bar test, result in the correct data dump in my /tmp/log
    – JohnT
    May 6, 2011 at 11:33
  • You're probably right about optimizing afterward. I added an untested example in shell script in case you find it helpful. May 6, 2011 at 11:37
  • Hi, thank you for the example, it's working, however I need to find a way to get that line in my php script, I tried both special variable $argv & STDIN but not result, thank you !
    – JohnT
    May 6, 2011 at 11:47

Your Answer

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

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