What is the default apache2 log format and where is defined such default?

13,832

Solution 1

It is clearly stated in the documetation for the TransferLog statement:

This directive has exactly the same arguments and effect as the CustomLog directive, with the exception that it does not allow the log format to be specified explicitly or for conditional logging of requests. Instead, the log format is determined by the most recently specified LogFormat directive which does not define a nickname. Common Log Format is used if no other format has been specified.

Go on to the LogFormat statement:

Default: LogFormat "%h %l %u %t \"%r\" %>s %b"

So if a TransferLog statement is given without any LogFormat statement the output format is as described above.

If also the TransferLog statment is missing no access log is written.

Solution 2

For Ubuntu 16.04, you can find the global configuration file here:

/etc/apache2/apache2.conf

Therein it defines some LogFormat directives.

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

The out-of-the-box virtual host configuration file is here:

/etc/apache2/sites-available/000-default.conf

And inside you will find that it declares:

CustomLog ${APACHE_LOG_DIR}/access.log combined

The combined alias refers to the second LogFormat in the aforementioned global config:

"%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""

Solution 3

Default LogFormat is indeed really

Default: LogFormat "%h %l %u %t \"%r\" %>s %b"

But the log format apache uses by default (on Debian distro at least) is:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
Share:
13,832

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I review (a fast reading) Apache Module mod_log_config and can't figure out what is the apache2 default log format and where is defined it. Any idea?

    Note that what is on

    /etc/apache2/conf.d/other-vhosts-access-log

    is not a default option but a global option.

  • user785287
    user785287 about 11 years
    Thanks, but still can't read anything about TransferLog default, I mean, are you saying that if no CustomLog is specified, the TransferLog directive is in charge even it is not specified? If that is the case, where do you read that? cos TransferLog hasn't a default section defined. Thanks again.
  • H.-Dirk Schmitt
    H.-Dirk Schmitt about 11 years
    If no TransferLog is defined, it is not written.
  • Jeff Puckett
    Jeff Puckett almost 8 years
    This has changed ever so slightly for Ubuntu 16.04 from %b "Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent." to now %O "Bytes sent, including headers. May be zero in rare cases such as when a request is aborted before a response is sent. You need to enable mod_logio to use this."