Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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
share|improve this answer
    
That's exactly what is was hoping for, thanks! –  Chris Aug 31 '11 at 16:12
add comment

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.

share|improve this answer
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.