How to understand the LogFormat directive in the apache2.conf configuration file?

In the comments before the LogFormat directive is used the following is written:

# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.

Then:

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

What does all of that mean and why do we need that?

Detailed but simple as possible explanations are preferred.

Answers 1

  • Apache mentions that those log formats use slightly deviate from CLF for the reasons mentioned. I don't think it should matter much as they are rather similar and tools will parse them. You can use those logformats for custom logs, e.g.:

    CustomLog logs/access_log common
    

    This way you can reuse log formats e.g. for virtual hosts instead of having to specify them inplace. Those above are the common predefined log format. You can specify as many as you like.


Related Questions