I would like to set up custom logging for my vhosts in Apache 2.2:

What I'm looking for is a way to define a custom log format (once) that I can then use as the format for all of my vhost's configs custom logs.

Can I define the log format at the top of my vhost.conf file then refer to it within each vhost directive (Or do I define it in the main httpd.conf)? -- OR do I have to define it once for each vhost block?



Are you asking just for the log format definition in one place?

In your main server config, use the LogFormat directive:

LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common

Note the end vhost_common is the nickname.

Then, you can specify in each vhost block to use that format for the log:

CustomLog logs/myvhost.access.log vhost_common

Edited: Looked it up:

You can define a log format with the LogFormat directive in your main config file and then use the CustomLog statement inside your vHost files.

Also, at the very least you can include the same snippet defining your log format as an include into the config segment of each of your vHosts the same way you include those into the main httpd.conf. This is possible with every kind of configuration that is the same for many vHosts.

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.