http-logger
Sends request logs to an HTTP endpoint in batches.
http-loggerPriority 410What it does
http-logger sends the records of the requests that reach the route or other object it is added to, to an HTTP endpoint, the URI. The records are collected on the gateway node and sent in batches, each one a POST to that address, so one call to the endpoint can carry several records.
A Log format of your own replaces the default record with the fields you name. It is set here or, for the whole environment, in the plugin metadata. Log format extra adds fields to the default record only, and is not read while a Log format is set.
When to use it
- Request records have to reach a collector the operations team runs behind an HTTP endpoint, for example
https://logs.example.com/gateway/entries. - A small service of your own should receive the records of one route, the orders API for example, to keep its own audit of who called it.
- Every record in the environment should carry the same few fields, the client address, method, path, status and backend time, set once in the plugin metadata.
- The collector accepts records only with an
Authorizationheader that carries a token.
Not for records sent to a Kafka topic — see kafka-logger (Sends request logs to a Kafka topic), records kept in Elasticsearch — see elasticsearch-logger (Sends request logs to an Elasticsearch index) or records sent to a syslog server — see syslog (Sends request logs to a syslog server).
Set it up
Send request records in batches to an HTTP collector
auth_header is the whole Authorization value the collector receives, scheme included, so for a bearer token write Bearer, a space and the token.
Under Basics set URI to https://logs.example.com/gateway/entries and set Auth header to <secret>. Under Behavior set Timeout to 5 seconds and turn on SSL verify. Under Advanced set Batch size to 500 and set Buffer duration to 30 seconds.
{
"uri": "https://logs.example.com/gateway/entries",
"auth_header": "<secret>",
"batch_max_size": 500,
"buffer_duration": 30,
"timeout": 5,
"ssl_verify": true
}
More scenarios
Choose the fields every request record carriesenvironment-wide settings
Fill Log format as in the JSON below.
{
"log_format": {
"client": "$remote_addr",
"method": "$request_method",
"path": "$uri",
"status": "$status",
"upstream_seconds": "$upstream_response_time"
}
}
Things to know
- URI — The records arrive as a
POSTto the path of this address,/gateway/entriesin the example. - URI — An address without its scheme,
http://orhttps://, is refused when you save. - Auth header — The value is the whole
Authorizationheader the collector receives, scheme included. For a bearer token writeBearer, a space and the token. - Batch size — A batch goes out when it holds Batch size records, when its first record has waited Buffer duration, or when nothing new arrived for Inactive timeout.
- Concat method — Only
jsonandnew_lineare accepted;csvis refused when you save. - Timeout — A whole number of seconds: a fraction,
1.5for example, is refused when you save. - A log format in the plugin metadata reaches the records of a route whose http-logger names none of its own. A
GETis then recorded withmethodset toGET, and every record carriesupstream_seconds. - Log format extra — Added to the default record only: while a log format is set, on this object or in the plugin's metadata, the engine writes that format alone and reads nothing here.
- Pending entry limit — While more entries than this wait to be sent, new ones are dropped rather than queued.
- Include request body when — The console’s form draws one level of conditions; a value that nests deeper is kept as it is and edited in Raw JSON.
- Include response body when — The console’s form draws one level of conditions; a value that nests deeper is kept as it is and edited in Raw JSON.
- Auth header — Each batch reaches the collector with an
Authorizationheader carrying this value. - AdviceTurn on the request and response bodies only on routes whose collector is meant to hold what clients and the backend send.
Settings
The fields as the console shows them, section by section.
Basics
uristringRequiredpattern
^[^\/]+:\/\/([\da-zA-Z.-]+|\[[\da-fA-F:]+\])(:\d+)?http://logs.internal:8080/entriesauth_headerstringStored on the engine and shown only to roles that manage this object.
Behavior
concat_methodstringdefault jsontimeoutintegerdefault 3ssl_verifybooleandefault falselog_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}include_req_bodybooleandefault falseinclude_req_body_exprarrayinclude_resp_bodybooleandefault falseinclude_resp_body_exprarraymax_req_body_bytesintegerdefault 524288max_resp_body_bytesintegerdefault 524288Advanced
batch_max_sizeintegerdefault 1000buffer_durationintegerdefault 60inactive_timeoutintegerdefault 5max_retry_countintegerdefault 0retry_delayintegerdefault 1namestringdefault http loggerEnvironment-wide settings
Set once per environment, under Plugins › http-logger. Every http-logger in the environment uses these.
log_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}max_pending_entriesintegerdefault 8192How many log entries may wait to be sent. While the backlog is above this number, new entries are dropped rather than queued.