Mod_log_config - Apache Http Server
Mod_log_config - Apache Http Server
The characteristics of the request itself are logged by placing "%" directives in the format string, which are replaced in the log file by the values as follows:
These tokens can not be combined with each other or strftime(3) formatting in the same format string. You can use multiple %{format}t tokens
instead. The extended strftime(3) tokens are available with APAR PI49165.
%T The time taken to serve the request, in seconds.
%{UNIT}T The time taken to serve the request, in a time unit given by UNIT. Valid units are ms for milliseconds, us for microseconds, and s for seconds. Using s
gives the same result as %T without any format; using us gives the same result as %D. Combining %T with a unit is available with APAR PI49165.
%u Remote user (from auth; may be bogus if return status (%s) is 401)
%U The URL path requested, not including any query string.
%v The canonical ServerName of the server serving the request.
%V The server name according to the UseCanonicalName setting.
%X Connection status when response is completed:
X = connection aborted before the response completed.
+ = connection may be kept alive after the response is sent.
- = connection will be closed after the response is sent.
(This directive was %c in late versions of Apache 1.3, but this conflicted with the historical ssl %{var}c syntax.)
%I Bytes received, including request and headers, cannot be zero. You need to enable mod_logio to use this.
%O Bytes sent, including headers, cannot be zero. You need to enable mod_logio to use this.
% The contents of VARNAME: trailer line(s) in the request sent to the server.
{VARNAME}^ti
% The contents of VARNAME: trailer line(s) in the response sent from the server.
{VARNAME}^to
Modifiers
Particular items can be restricted to print only for responses with specific HTTP status codes by placing a comma-separated list of status codes immediately following the
"%". For example, "%400,501{User-agent}i" logs User-agent on 400 errors and 501 errors only. For other status codes, the literal string "-" will be logged. The status
code list may be preceded by a "!" to indicate negation: "%!200,304,302{Referer}i" logs Referer on all requests that do not return one of the three specified codes.
The modifiers "<" and ">" can be used for requests that have been internally redirected to choose whether the original or final (respectively) request should be consulted.
By default, the % directives %s, %U, %T, %D, and %r look at the original request while all others look at the final request. So for example, %>s can be used to record the
final status of the request and %<u can be used to record the original authenticated user on a request that is internally redirected to an unauthenticated resource.
Some Notes
For security reasons, starting with version 2.0.46, non-printable and other special characters in %r, %i and %o are escaped using \xhh sequences, where hh stands for the
hexadecimal representation of the raw byte. Exceptions from this rule are " and \, which are escaped by prepending a backslash, and all whitespace characters, which are
written in their C-style notation (\n, \t, etc). In versions prior to 2.0.46, no escaping was performed on these strings so you had to be quite careful when dealing with raw
log files.
In httpd 2.0, unlike 1.3, the %b and %B format strings do not represent the number of bytes sent to the client, but simply the size in bytes of the HTTP response (which will
differ, for instance, if the connection is aborted, or if SSL is used). The %O format provided by mod_logio will log the actual number of bytes sent over the network.
Examples
Some commonly used log format strings are:
You can use the %{format}t directive multiple times to build up a time format using the extended format tokens like msec_frac:
Security Considerations
See the security tips document for details on why your security could be compromised if the directory where logfiles are stored is writable by anyone other than the user
that starts the server.
BufferedLogs Directive
Description: Buffer log entries in memory before writing to disk
Syntax: BufferedLogs On|Off
Default: BufferedLogs Off
Context: server config
Status: Base
Module: mod_log_config
Compatibility: Available in versions 2.0.41 and later.
The BufferedLogs directive causes mod_log_config to store several log entries in memory and write them together to disk, rather than writing them after each request.
On some systems, this may result in more efficient disk access and hence higher performance. It may be set only once for the entire server; it cannot be configured per
virtual-host.
CookieLog Directive
Description: Sets filename for the logging of cookies
Syntax: CookieLog filename
Context: server config, virtual host
Status: Base
Module: mod_log_config
Compatibility: This directive is deprecated.
The CookieLog directive sets the filename for logging of cookies. The filename is relative to the ServerRoot. This directive is included only for compatibility with
mod_cookies, and is deprecated.
CustomLog Directive
Description: Sets filename and format of log file
Syntax: CustomLog file|pipe format|nickname [env=[!]environment-variable]
Context: server config, virtual host
Status: Base
Module: mod_log_config
The CustomLog directive is used to log requests to the server. A log format is specified, and the logging can optionally be made conditional on request characteristics using
environment variables.
The first argument, which specifies the location to which the logs will be written, can take one of the following two types of values:
file
A filename, relative to the ServerRoot.
pipe
The pipe character "|", followed by the path to a program to receive the log information on its standard input.
Security:
If a program is used, then it will be run as the user who started httpd. This will be root if the server was started by root; be sure that the program is secure.
Note
When entering a file path on non-Unix platforms, care should be taken to make sure that only forward slashed are used even though the platform may allow
the use of back slashes. In general it is a good idea to always use forward slashes throughout the configuration files.
Note
If you use a piped logger for the ErrorLog defined in the base server configuration , and your piped logger is unable to write to the logfile it's configured for,
no error reporting from the server or the piped logging program will be available.
The second argument specifies what will be written to the log file. It can specify either a nickname defined by a previous LogFormat directive, or it can be an explicit format
string as described in the log formats section.
For example, the following two sets of directives have exactly the same effect:
Environment variables can be set on a per-request basis using the mod_setenvif and/or mod_rewrite modules. For example, if you want to record requests for all GIF
images on your server in a separate logfile but not in your main log, you can use:
Or, to reproduce the behavior of the old RefererIgnore directive, you might use the following:
LogFormat Directive
Description: Describes a format for use in a log file
Syntax: LogFormat format|nickname [nickname]
Default: LogFormat "%h %l %u %t \"%r\" %>s %b"
Context: server config, virtual host
Status: Base
Module: mod_log_config
The LogFormat directive can take one of two forms. In the first form, where only one argument is specified, this directive sets the log format which will be used by logs
specified in subsequent TransferLog directives. The single argument can specify an explicit format as discussed in the custom log formats section above. Alternatively, it
can use a nickname to refer to a log format defined in a previous LogFormat directive as described below.
The second form of the LogFormat directive associates an explicit format with a nickname. This nickname can then be used in subsequent LogFormat or CustomLog
directives rather than repeating the entire format string. A LogFormat directive that defines a nickname does nothing else -- that is, it only defines the nickname, it
doesn't actually apply the format and make it the default. Therefore, it will not affect subsequent TransferLog directives. In addition, LogFormat cannot use one nickname
to define another nickname. Note that the nickname should not contain percent signs (%).
Example
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
TransferLog Directive
Description: Specify location of a log file
Syntax: TransferLog file|pipe
Context: server config, virtual host
Status: Base
Module: mod_log_config
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.
Example
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
TransferLog logs/access_log
Copyright 2007 The Apache Software Foundation. Modules | Directives | FAQ | Glossary | Sitemap
Licensed under the Apache License, Version 2.0.