Default logs in JSON

#1

Hi,

What is the best way to change the format of logs to json.
By default Kong as nginx_acc_logs and nginx_err_logs with a string format A - B - C - D.

the documentation is not very clear, can you help on this.

#2

Solved, i´ve created a new custom-nginx.template with this:

http {
log_format json_combined escape=json
‘{’
‘“time_local”:"$time_iso8601",’
‘“remote_addr”:"$remote_addr",’
‘“request”:"$request",’
‘“status”: “$status”,’
‘“request_time”:"$request_time",’
‘“connection_requests”:"$connection_requests",’
‘“http_user_agent”:"$http_user_agent"’
‘}’;

access_log ${{PROXY_ACCESS_LOG}} json_combined;

include ‘nginx-kong-template.conf’;
}

and on start do kong start -c kong.yml --nginx-conf custom-nginx.template

3 Likes
#3

Interesting! It can become a plugin :slight_smile:

#4

Neat trick for those who want json output web server logs as opposed to the usual, nicely done.

#5

It will more easy if we can put the log format pattern on global config.
I will do a pull request with this as soon as possible.

#6

This only changes the format of access logs to json.
Did you find a way to also change the format of error logs to json?

#7

is not supported by nginx change error logs