How to generate a JSON log from nginx?

This question shows research effort; it is useful and clear

57

This question does not show any research effort; it is unclear or not useful

Show activity on this post.

I'm trying to generate a JSON log from nginx.

I'm aware of solutions like this one but some of the fields I want to log include user generated input (like HTTP headers) which need to be escaped properly.

I'm aware of the nginx changelog entries from Oct 2011 and May 2008 that say:

*) Change: now the 0x7F-0x1F characters are escaped as \xXX in an access_log.
*) Change: now the 0x00-0x1F, '"' and '\' characters are escaped as \xXX in an access_log.

but this still doesn't help since \xXX is invalid in a JSON string.

I've also looked at the HttpSetMiscModule module which has a set_quote_json_str directive, but this just seems to add \x22 around the strings which doesn't help.

Any idea for other solutions to log in JSON format from nginx?

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.125.0. UTC+08:00, 2024-05-05 05:54
浙ICP备14020137号-1 $访客地图$