Skip to main content

File Logger Configuration

The file-logger plugin writes gateway request and response logs as newline-delimited JSON files for local collection and troubleshooting. Configuration covers plugin parameters and plugin metadata.

Parameters​

See plugin common configurations for configuration options available to all plugins.

  • path

    string


    Path of the file to append newline-delimited JSON log entries to. The parent directory must exist and be writable by the gateway process.

    A path configured on the plugin instance takes precedence over plugin metadata.

    API7 Gateway 3.9.25 requires path on every plugin instance. API7 Gateway 3.10.11 and APISIX 3.21.0 can inherit it from plugin metadata.

  • log_format

    object


    Custom log entry using key-value pairs. Values can reference built-in variables. Configuring this field replaces the default log format.

    Route and service identifiers are included automatically when available.

    APISIX supports nested structures up to five levels and truncates deeper content. API7 Gateway supports flat key-value structures.

    A value configured on the plugin instance takes precedence over plugin metadata.

  • log_format_extra

    object


    Additional fields to add to the default log entry. Values can reference built-in variables, and existing default fields are not overwritten.

    A plugin instance takes precedence over plugin metadata. When log_format is configured, log_format_extra is ignored.

    Introduced in API7 Enterprise 3.9.15 and 3.10.2, and in APISIX 3.18.0.

  • include_req_body

    boolean

    default: false


    If true, include the request body in the default log entry. Use max_req_body_bytes to limit the logged body size.

  • include_req_body_expr

    array[array]

    valid value:

    at least one condition

    Conditions in APISIX expression format that control proactive body reading and the default request.body field. Used only when include_req_body is true.

    A custom format that references $request_body can still include a body already buffered by NGINX when the conditions are false. Do not use this field as a data-redaction boundary.

  • include_resp_body

    boolean

    default: false


    If true, include the response body in the default log entry. Use max_resp_body_bytes to limit the logged body size.

  • include_resp_body_expr

    array[array]

    valid value:

    at least one condition

    Conditions in APISIX expression format that control when the response body is logged. Used only when include_resp_body is true.

  • max_req_body_bytes

    integer

    default: 524288

    valid value:

    greater than or equal to 1

    Maximum request body size, in bytes, to include in a log entry. Longer bodies are truncated.

  • max_resp_body_bytes

    integer

    default: 524288

    valid value:

    greater than or equal to 1

    Maximum response body size, in bytes, to include in a log entry. Longer bodies are truncated.

  • match

    array[array]

    valid value:

    up to 20 expressions

    One or more APISIX expressions. A log entry is written when any expression matches the request.

Plugin Metadata​

  • path

    string


    Default log file path for plugin instances that omit path.

    API7 Gateway 3.9.25 requires path on every plugin instance. API7 Gateway 3.10.11 and APISIX 3.21.0 can inherit it from plugin metadata.

  • log_format

    object


    Custom log entry used by plugin instances that do not configure log_format. Values can reference built-in variables.

    Configuring log_format on a plugin instance takes precedence.

  • log_format_extra

    object


    Additional fields added to the default entry for plugin instances that omit log_format_extra. Existing default fields are not overwritten.

    Configuring log_format_extra on a plugin instance, including an empty object, takes precedence. When log_format is configured, log_format_extra is ignored.