sqlitelog_format

Defines a log format for storing access logs in an SQLite database.

Syntaxsqlitelog_format name format_string;
Defaultnone
Contexthttp
Arguments2+

Description

The sqlitelog_format directive specifies a custom format for logging HTTP access requests to a specified SQLite database. The format can include various variables that correspond to details of the HTTP request, such as the client's IP address, the requested URI, and the status code returned by the server. This directive is especially useful for structuring logs in a way that makes querying the SQLite database straightforward and efficient.

In its usage, the sqlitelog_format directive accepts two or more parameters. The first parameter is the format name, which is used to identify this format across your NGINX configuration. The subsequent parameters comprise a series of variables that define what information should be logged. These variables can include elements like $remote_addr for the client's IP address, $time_local for the timestamp, and any other NGINX log variables available, allowing for comprehensive logging tailored to user needs. Once defined, this format can be referenced by the sqlitelog directive when specifying how access logs should be recorded in the SQLite database.

It is important to note that if the defined format is too intricate or the log entries become overly complex, performance could potentially be impacted, especially under high-load scenarios. Additionally, the specified format influences how data is stored in the SQLite database, so careful planning of the format structure is advisable based on query needs and expected log analysis workflows.

Config Example

http {
    sqlitelog_format myformat "$remote_addr $time_local $request_uri $status $bytes_sent";
    sqlitelog /tmp/access.db myformat buffer=128K max=5;
}

If no format is specified, logs will not be written correctly, potentially leading to data loss.

Improper configuration or undefined variables in the format string can result in errors or empty log entries.

Ensure that the SQLite database is writable by the NGINX process to avoid logging issues.

← Back to all directives