view xml/cn/docs/http/ngx_http_log_module.xml @ 1017:9f9a427a73eb

Fixed broken links to chinese versions of some modules. The chinese version contains untranslated copies of english documentation for random_index and realip modules. The result is the appearance of 'translation to chinese' link for this modules pointing to non-existing document. This files are removed. Also, broken links are generated for the chinese version of the "flv" module, but the translation exists, although not enabled for publication. Since contents of file looks like a valid translation, it is allowed to be published.
author Vladimir Homutov <vl@nginx.com>
date Mon, 18 Nov 2013 12:48:10 +0400
parents ceb8a4e374b7
children
line wrap: on
line source

<?xml version="1.0"?>

<!--
  Copyright (C) Igor Sysoev
  Copyright (C) Nginx, Inc.
  -->

<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">

<module name="ngx_http_log_module模块"
        link="/cn/docs/http/ngx_http_log_module.html"
        lang="cn"
        translator="nigelzeng"
        rev="3">

<section id="summary">

<para>
<literal>ngx_http_log_module</literal>模块按指定的格式写访问日志。
</para>

<para>
请求在处理结束时,会按请求路径的配置上下文记访问日志。
如果在请求处理期间产生了<link doc="ngx_http_core_module.xml" id="internal">内部跳转</link>,
请求结束时的路径可能不同于原始的请求路径。
</para>

</section>


<section id="example" name="配置实例">

<para>
<example>
log_format gzip '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" "$gzip_ratio"';

access_log /spool/logs/nginx-access.log gzip buffer=32k;
</example>
</para>

</section>


<section id="directives" name="指令">

<directive name="access_log">
<syntax>
    <value>path</value>
    [<value>format</value>
    [<literal>buffer</literal>=<value>size</value>]]</syntax>
<syntax><literal>off</literal></syntax>
<default>logs/access.log combined</default>
<context>http</context>
<context>server</context>
<context>location</context>
<context>if in location</context>
<context>limit_except</context>

<para>
为访问日志设置路径,格式和缓冲区大小(nginx访问日志支持缓存)。
在同一个配置层级里可以指定多个日志。
特定值<literal>off</literal>会取消当前配置层级里的所有<literal>access_log</literal>指令。
如果没有指定日志格式则会使用预定义的“<literal>combined</literal>”格式。
</para>

<para>
缓冲区的大小不能超过磁盘文件原子性写入的大小。
对于FreeBSD来说缓冲区大小是无限制的。
</para>

<para>
日志文件的路径可以包含变量(0.7.6+),
但此类日志存在一些限制:
<list type="bullet">

<listitem>
工作进程使用的<link doc="../ngx_core_module.xml" id="user"/>
应拥有在目录里创建文件的权限;
</listitem>

<listitem>
写缓冲无效;
</listitem>

<listitem>
每条日志写入都会打开和关闭文件。然而,频繁使用的文件描述符可以存储在
<link id="open_log_file_cache">缓存</link>中,
在<link id="open_log_file_cache"/>指令的<literal>valid</literal>参数指定的时间里,
写操作能持续写到旧文件。
</listitem>

<listitem>
每次日志写入的操作都会检查请求的
<link doc="ngx_http_core_module.xml" id="root">根目录</link>是否存在,
如果不存在则日志不会被创建。
因此在一个层级里同时指定<link doc="ngx_http_core_module.xml" id="root"/>
和<literal>access_log</literal>是一个不错的想法:
<example>
server {
    root       /spool/vhost/data/$host;
    access_log /spool/vhost/logs/$host;
    ...
</example>
</listitem>

</list>
</para>

</directive>


<directive name="log_format">
<syntax>
    <value>name</value>
    <value>string</value> ...</syntax>
<default>combined "..."</default>
<context>http</context>

<para>
指定日志的格式。
</para>

<para>
日志格式允许包含普通变量和只在日志写入时存在的变量:
<list type="tag">

<tag-name><var>$body_bytes_sent</var></tag-name>
<tag-desc>
发送给客户端的字节数,不包括响应头的大小;
该变量与Apache模块<literal>mod_log_config</literal>里的“<literal>%B</literal>”参数兼容。
</tag-desc>

<tag-name><var>$bytes_sent</var></tag-name>
<tag-desc>
发送给客户端的总字节数。
</tag-desc>

<tag-name><var>$connection</var></tag-name>
<tag-desc>
连接的序列号。
</tag-desc>

<tag-name><var>$connection_requests</var></tag-name>
<tag-desc>
当前通过一个连接获得的请求数量。
</tag-desc>

<tag-name><var>$msec</var></tag-name>
<tag-desc>
日志写入时间。单位为秒,精度是毫秒。
</tag-desc>

<tag-name><var>$pipe</var></tag-name>
<tag-desc>
如果请求是通过HTTP流水线(pipelined)发送,pipe值为“<literal>p</literal>”,否则为“<literal>.</literal>”。
</tag-desc>

<tag-name><var>$request_length</var></tag-name>
<tag-desc>
请求的长度(包括请求行,请求头和请求正文)。
</tag-desc>

<tag-name><var>$request_time</var></tag-name>
<tag-desc>
请求处理时间,单位为秒,精度毫秒;
从读入客户端的第一个字节开始,直到把最后一个字符发送给客户端后进行日志写入为止。
</tag-desc>

<tag-name><var>$status</var></tag-name>
<tag-desc>
响应状态。
</tag-desc>

<tag-name><var>$time_iso8601</var></tag-name>
<tag-desc>
ISO8601标准格式下的本地时间。
</tag-desc>

<tag-name><var>$time_local</var></tag-name>
<tag-desc>
通用日志格式下的本地时间。
</tag-desc>

</list>
</para>

<para>
发送给客户端的响应头拥有“<literal>sent_http_</literal>”前缀。
比如<var>$sent_http_content_range</var>。
</para>

<para>
配置始终包含预先定义的“<literal>combined</literal>”日志格式:
<example>
log_format combined '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';
</example>
</para>

</directive>


<directive name="open_log_file_cache">

<syntax>
<literal>max</literal>=<value>N</value>
[<literal>inactive</literal>=<value>time</value>]
[<literal>min_uses</literal>=<value>N</value>]
[<literal>valid</literal>=<value>time</value>]</syntax>
<syntax><literal>off</literal></syntax>
<default>off</default>
<context>http</context>
<context>server</context>
<context>location</context>

<para>
定义一个缓存,用来存储频繁使用的文件名中包含变量的日志文件描述符。
该指令包含以下参数:
<list type="tag">

<tag-name><literal>max</literal></tag-name>
<tag-desc>
设置缓存中描述符的最大数量;如果缓存被占满,最近最少使用(LRU)的描述符将被关闭。
</tag-desc>

<tag-name><literal>inactive</literal></tag-name>
<tag-desc>
设置缓存文件描述符在多长时间内没有被访问就关闭;
默认为10秒。
</tag-desc>

<tag-name><literal>min_uses</literal></tag-name>
<tag-desc>
设置在<literal>inactive</literal>参数指定的时间里,
最少访问多少次才能使文件描述符保留在缓存中;默认为1。
</tag-desc>

<tag-name><literal>valid</literal></tag-name>
<tag-desc>
设置一段用于检查超时后文件是否仍以同样名字存在的时间;
默认为60秒。
</tag-desc>

<tag-name><literal>off</literal></tag-name>
<tag-desc>
禁用缓存。
</tag-desc>

</list>
</para>

<para>
使用实例:
<example>
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
</example>
</para>

</directive>

</section>

</module>