Use JSON format for plugin logs

Nginx allows to override the default access_logs format via the log_format directive. We are using this feature to get Nginx logs in a JSON format.

However, as noted in kong.log docs, plugin logs are reported to the Nginx error_log directive. AFAIK, there is no option to set error_log format.

Is there any workaround we can use to get plugins output in a JSON format?

1 Like

Hi, there is indeed no built-in way to customize the error_log format. I have seen some options but I don’t take this as a recommendation, as I haven’t tried them myself:

Thanks for answering

I’m not sure how we can use those options for plugins logs:

We are logging info in the plugins, not only errors. So we actually don’t have a status code to work with…

Do you mean to alter the log files themselves after they are generated? It is doable but really complicates the whole logging process :thinking:

Right. You can’t use the “error code escape” then.

I was not proposing modifying the log files. The exact solution will depend on your sytem. You could do a very simple demon which translates every new line on the logs to a JSON line in a different, separate file, and then use that to feed your system. Or you could batch the json requests, aggregate them in memory, and periodically send your aggregator a POST request, if it accepts that.