Skip to main content

Module log_entry

Module log_entry 

Source
Expand description

Shared access-log entry builder for the logger plugins.

Every logger (http-logger, tcp-logger, elasticsearch-logger, …) turns the request Context into the same JSON entry so their output is consistent. Two shapes, mirroring APISIX’s log-util:

  • default entry — a structured object (request, response, client_ip, latency, consumer, …) when no log_format is set.
  • custom entry — a flat object built from a configured log_format map of name -> "template", each pre-parsed into a Template at config load and rendered per request via Template::render_with_legacy (supports {{namespace.path}} references plus legacy $var interpolation).

Latency is derived from the reserved __request_start_ms message key the data-plane listener stamps at request start; it is omitted when absent (e.g. in unit tests that build a Context directly).

Enums§

LogFormatValue
One entry in a parsed LogFormat: a string value is pre-parsed into a Template at config-load time (one parse, per-request render); a number/boolean scalar is kept as-is and rendered verbatim.

Functions§

build_custom 🔒
build_default 🔒
build_entry
Builds a log entry for ctx.
client_ip 🔒
Client IP without the port.
headers_to_json 🔒
Header map → JSON object of name -> [values].
latency_ms 🔒
Milliseconds elapsed since the listener stamped __request_start_ms.
parse_log_format
Parses a log_format config value (an object of name -> string) into a LogFormat, or None when absent. Returns an error if it is present but not an object of scalar values. String values are pre-parsed into Templates here (warnings discarded — the compile-time walk, a later task, reports them); number/boolean values pass through unchanged.
reads_response_body
Whether a logger with this configuration reads context.response.body.
request_uri 🔒
Path plus sorted query string.

Type Aliases§

LogFormat
A parsed log_format: entry name -> pre-parsed value.