Skip to content

Access Logger ​

Sword can log one line per request once the response is sent. The line includes the method, the URI, the status, the latency and the request id. This is separate from the global [tracing] subscriber and is driven entirely by the [web.logger] section.

The logger is off unless the section is present.

Configuration ​

toml
[web.logger]
enabled = true
level = "auto"
skip-paths = ["/api/health"]
log-query = false
KeyTypeDefaultDescription
enabledbooltrueEnables or disables the logger
levelauto | infoautoLog level policy. See Levels
skip-pathsString[][]Paths to exclude from logging (exact or prefix match)
log-queryboolfalseInclude the query string in the logged uri

Levels ​

  • info logs every request at INFO regardless of the status.
  • auto picks the level from the response status.
StatusLevel
2xx / 3xxINFO
4xxWARN
5xxERROR

Log fields ​

FieldDescription
statusHTTP status code.
latencyTime spent handling the request, formatted from Duration (e.g. 1.234ms).
request_idFirst 8 characters of x-request-id, or - when the header is missing.
messageMETHOD URI, including the query string only when log-query = true.

Requests matching skip-paths are neither measured nor logged.

Request ID ​

The logger reuses the x-request-id header set by the built-in RequestIdLayer. When present, it logs only the first 8 characters. Otherwise it uses a - placeholder.