I’m using Kong 3.3.0 dockerized container. I was able to turn off various fields and leave just the ones I needed by this:
curl -X POST http://localhost:8001/plugins \
--header "Content-Type: application/json" \
--data '{
"name": "file-log",
"config": {
"path": "/tmp/file.log",
"reopen": true,
"custom_fields_by_lua": {
"client_ip": "return nil",
"route": "return nil",
"upstream_status": "return nil",
"tries": "return nil",
"service": "return nil",
"response": "return nil",
"upstream_uri": "return nil",
"authenticated_entity": "return nil",
"consumer.created_at": "return nil",
"consumer.updated_at": "return nil",
"consumer.tags": "return nil",
"consumer.id": "return nil",
"consumer.custom_id": "return nil",
"latencies.request": "return nil",
"request.querystring": "return nil",
"request.method": "return nil",
"request.size": "return nil",
"request.url": "return nil",
"request.uri": "return nil",
"request.headers.connection": "return nil",
"request.headers.x-consumer-username": "return nil",
"request.headers.x-consumer-id": "return nil",
"request.headers.x-real-ip": "return nil",
"request.headers.postman-token": "return nil",
"request.headers.host": "return nil",
"request.headers.user-agent": "return nil",
"request.headers.accept": "return nil",
"request.headers.x-credential-identifier": "return nil",
"request.headers.x-forwarded-proto": "return nil",
"request.headers.x-consumer-custom-id": "return nil",
"request.headers.accept-encoding": "return nil"
}
}
}'
I don’t know how to synthesize new fields, though. Made a few basic attempts and it didn’t work out; anyways whatever I wanted was already included by the default plugin; I just had to get rid of all these extra params.
The output is a compact one-line json having the ip address, the username, unix timestamp, and some other things. And I prefer this json request body format for the api calls to Kong instead of the multipart form one - json is easier to code in as well.