file-logger
#
Descriptionfile-logger
is a plugin that pushes a stream of log data to a specified location. For example, the output path can be customized: logs/file.log
.
#
AttributesName | Type | Requirement | Default | Valid | Description |
---|---|---|---|---|---|
path | string | required | Customise the output file path |
#
How To EnableThis is an example of how to enable the file-logger
plugin for a specific route.
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "plugins": { "file-logger": { "path": "logs/file.log" } }, "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:9001": 1 } }, "uri": "/hello"}'
#
Test Pluginsuccess:
$ curl -i http://127.0.0.1:9080/helloHTTP/1.1 200 OK...hello, world
You can then find the file.log
file in the corresponding logs
directory.
#
MetadataName | Type | Requirement | Default | Valid | Description |
---|---|---|---|---|---|
log_format | object | optional | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} | Log format declared as key value pair in JSON format. Only string is supported in the value part. If the value starts with $ , it means to get APISIX variable or Nginx variable. |
#
Examplecurl http://127.0.0.1:9080/apisix/admin/plugin_metadata/file-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "log_format": { "host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr" }}'
It is expected to see some logs like that:
{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
#
Disable PluginRemove the corresponding json configuration in the plugin configuration to disable the file-logger
.
APISIX plugins are hot-reloaded, therefore no need to restart APISIX.
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "methods": ["GET"], "uri": "/hello", "plugins": {}, "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:9001": 1 } }}'