Apache: Is it possible to set a default custom log format to be used by all vhosts

apache-2.2loggingvirtualhost

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

Best Answer

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