From: Joshua Slive Date: Mon, 11 Dec 2000 21:00:59 +0000 (+0000) Subject: Major update of mod_log_config docs. X-Git-Tag: APACHE_2_0_ALPHA_9~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45643bc9c809ded38464b96a2e85f2afb78b57dc;p=apache Major update of mod_log_config docs. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87288 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_log_config.html b/docs/manual/mod/mod_log_config.html index c2d31774f3..f52e9c9f42 100644 --- a/docs/manual/mod/mod_log_config.html +++ b/docs/manual/mod/mod_log_config.html @@ -33,19 +33,21 @@ REL="Help" HREF="module-dict.html#ModuleIdentifier" REL="Help" >Module Identifier: config_log_module -
-Compatibility: Was an extension module prior to Apache 1.2.

Summary

+ +

This module provides for flexible logging of client requests. Logs +are written in a customizable format, and may be written directly to a +file, or to an external program. Conditional logging is provided so +that individual requests may be included or excluded from the logs +based on characteristics of the request.

+

Three directives are provided by this module: TransferLog to create a log file, LogFormat to set a custom format, -and CustomLog to define a log file and format in one go. +and CustomLog to define a log file and format in one step. The TransferLog and CustomLog directives can be used multiple times in each server to cause each request to be logged to multiple files. @@ -54,56 +56,25 @@ logged to multiple files.

Directives

- -

Compatibility notes

- -

Log File Formats

-Unless told otherwise with LogFormat the log files created by -TransferLog will be in standard "Common Log Format" -(CLF). The contents of each line in a CLF file are explained +

Unless told otherwise with LogFormat, the log files +created by TransferLog will be in standard "Common Log +Format" (CLF). The contents of each line in a CLF file are explained below. Alternatively, the log file can be customized (and if multiple log files are used, each can have a different format). Custom formats -are set with LogFormat and CustomLog. +are set with LogFormat and CustomLog.

Common Log Format

-The Common Log Format (CLF) file contains a separate line for each -request. A line is composed of several tokens separated by spaces: +

The Common Log Format (CLF) file contains a separate line for each +request. A line is composed of several tokens separated by spaces:

host ident authuser date request status bytes @@ -143,11 +114,16 @@ any headers.

Custom Log Formats

-The format argument to the LogFormat and -CustomLog is a string. This string is logged to the log -file for each request. It can contain literal characters copied into -the log files, and `%' directives which are replaced in the log file -by the values as follows: +

The format argument to the LogFormat and +CustomLog directives is a string. This string is logged +to the log file for each request. It can contain literal characters +copied into the log files and the c-type control characters "\n" and +"\t" to represent new-lines and tabs. Literal quotes and back-slashes +should be escaped with back-slashes.

+ +

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:

 %...a:          Remote IP-address
@@ -180,7 +156,7 @@ by the values as follows:
                 the status of the *original* request --- %...>s for the last.
 %...t:          Time, in common log format time format (standard english format)
 %...{format}t:  The time, in the form given by format, which should
-                be in strftime(3) format. (potentially localised)
+                be in strftime(3) format. (potentially localized)
 %...T:          The time taken to serve the request, in seconds.
 %...u:          Remote user (from auth; may be bogus if return status (%s) is 401)
 %...U:          The URL path requested.
@@ -188,66 +164,98 @@ by the values as follows:
 %...V:          The server name according to the UseCanonicalName setting.
 
-The `...' can be nothing at all (e.g., "%h %u %r %s %b"), or it can -indicate conditions for inclusion of the item (which will cause it -to be replaced with `-' if the condition is not met). Note that -there is no escaping performed on the strings from %r, %...i and -%...o; some with long memories may remember that I thought this was -a bad idea, once upon a time, and I'm still not comfortable with -it, but it is difficult to see how to `do the right thing' with all -of `%..i', unless we URL-escape everything and break with CLF. +

The "..." can be nothing at all (e.g., "%h %u %r %s +%b"), or it can indicate conditions for inclusion of the item +(which will cause it to be replaced with "-" if the condition is not +met). The forms of condition are a list of HTTP status codes, which +may or may not be preceded by "!". Thus, "%400,501{User-agent}i" logs +User-agent: on 400 errors and 501 errors (Bad Request, Not +Implemented) only; "%!200,304,302{Referer}i" logs Referer: on all +requests which did not return some sort of normal +status.

-

+

Note that there is no escaping performed on the strings from +%...r, %...i and %...o. This is mainly to comply with the requirements +of the Common Log Format. This implies that clients can insert +control characters into the log, so care should be taken when dealing +with raw log files.

-The forms of condition are a list of HTTP status codes, which may -or may not be preceded by `!'. Thus, `%400,501{User-agent}i' logs -User-agent: on 400 errors and 501 errors (Bad Request, Not -Implemented) only; `%!200,304,302{Referer}i' logs Referer: on all -requests which did not return some sort of normal status. +

Some commonly used log format strings are:

-

+

+
Common Log Format (CLF)
+
"%h %l %u %t \"%r\" %>s %b"
-Note that the common log format is defined by the string "%h %l -%u %t \"%r\" %>s %b", which can be used as the basis for -extending for format if desired (e.g., to add extra fields at the end). -NCSA's extended/combined log format would be "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"". +
Common Log Format with Virtual Host
+
"%v %h %l %u %t \"%r\" %>s %b"
-

+

NCSA extended/combined log format
+
"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
+ +
Referer log format
+
"%{Referer}i -> %U"
-Note that the canonical ServerName -and Port of the server serving the request -are used for %v and %p respectively. This -happens regardless of the -UseCanonicalName setting because +
Agent (Browser) log format
+
"%{User-agent}i"
+
+ +

Note that the canonical ServerName and Port of the server serving the request are +used for %v and %p respectively. This +happens regardless of the UseCanonicalName setting because otherwise log analysis programs would have to duplicate the entire vhost matching algorithm in order to decide what host really served -the request. +the request.

Using Multiple Log Files

-The TransferLog and CustomLog directives can -be given more than once to log requests to multiple log files. Each +

The TransferLog and CustomLog directives can +be given more than once to log requests to multiple log files. Unless +the conditional form of CustomLog is used, each request will be logged to all the log files defined by either of these -directives. +directives.

Use with Virtual Hosts

-If a <VirtualHost> section does not contain any +

If a <VirtualHost> section does not contain any TransferLog or CustomLog directives, the logs defined for the main server will be used. If it does contain one or more of these directives, requests serviced by this virtual host will only be logged in the log files defined within its definition, not in any of the main server's log files. -See the examples below. -

+See the examples below.

Security Considerations

-See the security tips +

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. -

+the user that starts the server.

+ +

Resetting the Log Files

+ +

The access log file typically grows 1MB or more for each 10,000 +requests. It will probably be necessary to move or delete the log +file on a regular basis. This cannot be done while the server is +still running, because Apache will continue writing to the old log +file. Instead, the server must be restarted after the log file is moved or +deleted so that it will open a new log.

+ +

A typical scenario is:

+ +
+   mv access_log access_log.old
+   apachectl graceful
+   # wait for all requests to the old server to complete
+   # before doing anything with access_log.old
+
+ +

Alternatively, log files can be rotated automatically be writing +them through a pipe to a program designed for that purpose.


@@ -269,22 +277,22 @@ the user that starts the server. Compatibility: Only available in Apache 1.2 and above

+>Compatibility: Only available in Apache 1.2 and above

-The CookieLog directive sets the filename for logging of cookies. +

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. -

+only for compatibility with mod_cookies, and is deprecated.


-

CustomLog directive

-CustomLog +directive +

Syntax: CustomLog file-pipe - format-or-nickname
+>Syntax: CustomLog file|pipe + format|nickname [env=[!]environment-variable]
Compatibility: Nickname only available in Apache 1.3 - or later + or later. Conditional logging available in 1.3.5 or later.
Module: mod_log_config -

-The first argument is the filename to which log records should be -written. This is used -exactly like the argument to -TransferLog; -that is, it is either a full path or relative to the current -server root. -

-

-The format argument specifies a format for each line of the log file. -The options available for the format are exactly the same as for -the argument of the LogFormat directive. If the format -includes any spaces (which it will do in almost all cases) it -should be enclosed in double quotes. -

-

-Instead of an actual format string, you can use a format nickname defined with -the -LogFormat -directive. -

- -
-

CustomLog (conditional) directive

-Syntax: CustomLog file-pipe - format-or-nickname - env=[!]environment-variable
-Context: server config, virtual host
-Status: Base
-Compatibility: Only available in Apache 1.3.5 - or later -
-Module: mod_log_config -

- -The behaviour of this form of the CustomLog directive is almost -identical to the standard CustomLog -directive. The difference is that the 'env=' clause controls -whether a particular request will be logged in the specified file or -not. If the specified environment variable is set for the -request (or is not set, in the case of a 'env=!name' -clause), then the request will be logged. -

-

-Environment variables can be set on a per-request basis -using the mod_setenvif and/or -mod_rewrite modules. For example, -if you don't want to record requests for all GIF images on -your server in a separate logfile but not your main log, you -can use: +>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 on 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 +under the user who started httpd. This will be root if the server was +started by root; be sure that the program is secure.
+
+ +

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:

+ +
+     # CustomLog with format nickname
+     LogFormat "%h %l %u %t \"%r\" %>s %b" common
+     CustomLog logs/access_log common
+
+     # CustomLog with explicit format string
+     CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"
+
+ +

The third argument is optional and allows the decision on whether +or not to log a particular request to be based on the presence or +absence of a particular variable in the server environment. If the +specified environment variable is set for +the request (or is not set, in the case of a +'env=!name' clause), then the request will be +logged.

+ +

Environment variables can be set on a per-request basis +using the mod_setenvif and/or mod_rewrite modules. For example, if you +don't want to record requests for all GIF images on your server in a +separate logfile but not your main log, you can use:

     SetEnvIf Request_URI \.gif$ gif-image
@@ -382,10 +375,11 @@ can use:
 

LogFormat directive

-Syntax: LogFormat format [nickname] +>Syntax: LogFormat format|nickname + [nickname]
Module: mod_log_config -

-This sets the format of the default logfile named by the -TransferLog -directive . See the section on -Custom Log Formats for details on the format -arguments. -

-

-If you include a nickname for the format on the directive line, you can -use it in other LogFormat and -CustomLog -directives rather than repeating the entire format string. -

-

-A +>Module: mod_log_config

+ +

This directive specifies the format of the access log file.

+ +

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 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 which 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. +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.


TransferLog directive

-Syntax: TransferLog file-pipe
+>Syntax: TransferLog file|pipe
Module: mod_log_config

- -The TransferLog directive adds a log file in the format defined by the -most recent -LogFormat -directive, or Common Log Format if no other default format has been -specified. -File-pipe is one -of -

A filename -
A filename relative to the ServerRoot. -
`|' followed by a command -
A program to receive the agent log information on its standard input. -Note the a new program will not be started for a VirtualHost if it inherits -the TransferLog from the main server. -
-Security: if a program is used, then it will be -run under the user who started httpd. This will be root if the server -was started by root; be sure that the program is secure.

+>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 specified LogFormat directive. 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\""
+   TranferLog logs/access_log
+