Log#
The module writes request logs in the specified format.
Logs are written in the context of a Default http, server, location, if in location, limit_except Sets the path, format and buffered write settings for the log. Multiple logs can be used at the same configuration level. Logging to syslog is configured by specifying the "syslog:" prefix in the first parameter. The special value off cancels all access_log directives for the current level. If no format is specified, the predefined "combined" format is used. If the buffer size is specified using the Warning The buffer size must not exceed the size of an atomic write to a disk file. For FreeBSD this size is unlimited. When buffering is enabled, data is written to the file: if the next log line does not fit in the buffer; if the data in the buffer has been there longer than the time interval specified by the flush parameter; when reopening the log file or terminating the worker process. If the Example: Note For gzip compression of logs support, Angie must be built with the zlib library. Variables can be used in the file path, but such logs have some limitations: the user under whose credentials the worker processes run must have permissions to create files in the directory with such logs; buffering does not work; the file is opened for each log write and closed immediately after writing. However, since descriptors of frequently used files can be stored in cache, during log rotation within the time specified by the valid parameter of the open_log_file_cache directive, writing may continue to the old file. for each log write, the existence of the root directory for the request is checked — if this directory does not exist, the log is not created. Therefore root and access_log should be described at the same configuration level: The Default http Specifies the log format. The When using When using Header lines sent to the client start with the prefix The predefined format Default http, server, location Defines a cache that stores file descriptors of frequently used logs whose names are specified using variables. Parameters: Sets the maximum number of descriptors in the cache; when the cache overflows, the least recently used (LRU) descriptors are closed. Sets the time after which a cached descriptor is closed if it has not been accessed during this time.
Default is 10 seconds. Sets the minimum number of file uses during the time specified by the Specifies after what time to check that the file still exists under the same name.
Default is 60 seconds. Disables caching. Usage example:location
where processing ends. This may be a location
different from the original one if an internal redirect occurs during request processing.Configuration Example#
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
access_log /spool/logs/angie-access.log compression buffer=32k;
Directives#
access_log#
access_log
path [format [buffer=
size] [gzip=
level]] [flush=
time] [if=
condition]];access_log
off
;access_log logs/access.log combined;
(path depends on the build parameter --http-log-path
)buffer
parameter or the gzip
parameter is specified, writing will be buffered.gzip
parameter is specified, the buffer will be compressed before writing to the file. The compression level can be set in the range from 1 (faster, but worse compression) to 9 (slower, but better compression). By default, a buffer size of 64K bytes and compression level 1 are used. Data is compressed in atomic blocks, and at any time the log file can be decompressed or read using the zcat utility.access_log /path/to/log.gz combined gzip flush=5m;
server {
root /spool/vhost/data/$host;
access_log /spool/vhost/logs/$host;
...
if
parameter enables conditional logging. A request will not be logged if the condition evaluation result is "0"
or an empty string. In the following example, requests with response codes 2xx and 3xx will not be logged:map $status $loggable {
~^[23] 0;
default 1;
}
access_log /path/to/access.log combined if=$loggable;
log_format#
log_format
name [escape
=:samp:default | json
| none
] string ...;log_format combined "...";
escape
parameter allows setting character escaping to json
or
default
in variables; by default default
is used.
The none
value disables character escaping.default
, characters """, "\", and characters with
values less than 32 or greater than 126 are escaped as "\xXX". If the
variable value is not found, a hyphen "-" will be written to the log as the value.json
, all characters not allowed in JSON
strings are escaped: characters """ and "\" are escaped as "\"" and "\\", characters with
values less than 32 are escaped as "\n", "\r", "\t", "\b", "\f", or
"\u00XX".sent_http_
,
for example, $sent_http_content_range
.combined
always exists in the configuration:log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
open_log_file_cache#
open_log_file_cache
max=
N [inactive=
time] [min_uses=
N] [valid=
time];open_log_file_cache
off
;open_log_file_cache off;
max
inactive
min_uses
inactive
parameter, after which the file descriptor will remain open in the cache.
Default is 1.valid
off
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;