Skip to main content

a6-plugin-http-logger

Overview

The http-logger plugin pushes request/response logs as JSON to HTTP or HTTPS endpoints. Logs are batched for efficiency and support custom formats using NGINX variables. Use it to send structured logs to any HTTP-based logging backend (Elasticsearch, Loki, custom APIs, etc.).

When to Use

  • Ship access logs to an HTTP-based logging backend
  • Custom log formats with selected fields only
  • Conditional request/response body capture
  • Batch log delivery with retry on failure

Plugin Configuration Reference

FieldTypeRequiredDefaultDescription
uristringYesHTTP/HTTPS endpoint for log delivery
auth_headerstringNoAuthorization header value
timeoutintegerNo3Connection timeout in seconds
log_formatobjectNoCustom log format (supports $variable syntax)
include_req_bodybooleanNofalseInclude request body in logs
include_req_body_exprarrayNoConditional expression for request body logging
include_resp_bodybooleanNofalseInclude response body in logs
include_resp_body_exprarrayNoConditional expression for response body logging
concat_methodstringNo"json"Batch format: json (array) or new_line (newline-separated)
ssl_verifybooleanNofalseVerify SSL certificate for HTTPS endpoints

Batch Processing Parameters

FieldTypeDefaultDescription
batch_max_sizeinteger1000Max entries per batch
inactive_timeoutinteger5Seconds before flushing incomplete batch
buffer_durationinteger60Max age of oldest entry before forced flush
max_retry_countinteger0Retry attempts on failure
retry_delayinteger1Seconds between retries

Default Log Entry Format

When no custom log_format is set, each log entry contains:

{
"client_ip": "127.0.0.1",
"route_id": "1",
"service_id": "",
"start_time": 1703907485819,
"latency": 101.9,
"apisix_latency": 100.9,
"upstream_latency": 1,
"upstream": "127.0.0.1:8080",
"request": {
"method": "GET",
"uri": "/api/users",
"url": "http://127.0.0.1:9080/api/users",
"size": 194,
"headers": { "host": "...", "user-agent": "..." },
"querystring": {}
},
"response": {
"status": 200,
"size": 123,
"headers": { "content-type": "...", "content-length": "..." }
},
"server": {
"hostname": "gateway-1",
"version": "3.15.0"
}
}

Step-by-Step: Ship Logs to an HTTP Endpoint

1. Create a route with http-logger

a6 route create -f - <<'EOF'
{
"id": "logged-api",
"uri": "/api/*",
"plugins": {
"http-logger": {
"uri": "http://log-collector:8080/logs",
"batch_max_size": 100,
"inactive_timeout": 10
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"backend:8080": 1
}
}
}
EOF

2. Verify logs are arriving

curl http://127.0.0.1:9080/api/hello
# Check your log collector for the entry

Common Patterns

Custom log format with NGINX variables

{
"plugins": {
"http-logger": {
"uri": "http://log-collector:8080/logs",
"log_format": {
"@timestamp": "$time_iso8601",
"client_ip": "$remote_addr",
"host": "$host",
"method": "$request_method",
"uri": "$request_uri",
"status": "$status",
"latency": "$request_time",
"upstream_addr": "$upstream_addr"
}
}
}
}

Authenticated endpoint

{
"plugins": {
"http-logger": {
"uri": "https://log-service.example.com/api/v1/logs",
"auth_header": "Bearer eyJhbGciOiJIUzI1NiIs...",
"ssl_verify": true,
"timeout": 5
}
}
}

Conditional request body logging

Log request bodies only when a query parameter is present:

{
"plugins": {
"http-logger": {
"uri": "http://log-collector:8080/logs",
"include_req_body": true,
"include_req_body_expr": [
["arg_debug", "==", "true"]
]
}
}
}

Newline-delimited JSON (for Elasticsearch bulk API)

{
"plugins": {
"http-logger": {
"uri": "http://elasticsearch:9200/_bulk",
"concat_method": "new_line"
}
}
}

Aggressive batching for high-traffic routes

{
"plugins": {
"http-logger": {
"uri": "http://log-collector:8080/logs",
"batch_max_size": 5000,
"inactive_timeout": 30,
"buffer_duration": 120,
"max_retry_count": 3,
"retry_delay": 2
}
}
}

Config Sync Example

version: "1"
routes:
- id: logged-api
uri: /api/*
plugins:
http-logger:
uri: http://log-collector:8080/logs
batch_max_size: 200
inactive_timeout: 10
log_format:
timestamp: "$time_iso8601"
client_ip: "$remote_addr"
method: "$request_method"
uri: "$request_uri"
status: "$status"
upstream_id: my-upstream

Troubleshooting

SymptomCauseFix
No logs arrivingWrong uri or endpoint downVerify endpoint is reachable from APISIX
SSL handshake failureCertificate not trustedSet ssl_verify: false for self-signed certs
Logs delayedLarge inactive_timeoutLower inactive_timeout for faster delivery
Logs droppedBuffer overflowIncrease batch_max_size; reduce delivery latency
Missing request bodyinclude_req_body: falseSet to true (caution: memory impact)
Auth rejectedWrong auth_header valueInclude full header value (e.g. Bearer <token>)

This page is generated from a6-plugin-http-logger/SKILL.md in the api7/a6 repository. Browse all skills on the AI Agent Skills page.