pipelog

The `pipelog` directive sends HTTP access log data to an external program via a pipe.

Syntaxpipelog command [format [nonblocking] [if=condition]]; pipelog off;
Defaultoff
Contexthttp, server, location, if in location, limit_except
Arguments1+

Description

The pipelog directive is a feature provided by the NGINX pipelog module that allows the integration of NGINX access logging with external programs. This directive can be placed within various contexts, including http, server, location, and conditions specified by if in location blocks or limit_except contexts. It supports a flexible syntax whereby users can specify an external command to execute, followed optionally by a logging format and additional parameters such as nonblocking to execute the log command without blocking the main request process.

Users are encouraged to define log formats with the pipelog_format directive, where they can describe how the log entries should be structured. The logs can be sent to any command that reads from standard input as a stream of text. The directive also allows for an if condition to control when logging should occur, enabling users to log selectively based on request attributes or other conditions. If provided, the logging format can reference multiple variables, akin to NGINX's built-in logging formats, allowing for customized log entries.

The directive is disabled by default and can be turned off explicitly with pipelog off;. Using this directive correctly requires attention to syntax and the requirements for the external command being executed, ensuring it can handle incoming log data appropriately.

Config Example

pipelog_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

pipelog "logger -t nginx" main;

Ensure that the external program specified by the command can read from the standard input and handle data appropriately.

Be cautious of performance implications when logging extensively via external commands, particularly in synchronous blocking modes.

Using if conditions can lead to unexpected behavior if not implemented correctly; ensure that conditions evaluate as expected.

← Back to all directives