问题原文
原帖链接 · SamBarham · CC BY-SA 3.0
We have Nginx as a reverse proxy in front of Tomcat. Both of them log access with ISO 8601 timestamps, but tomcat adds in milliseconds (which is part of the standard). So if Nginx gets a request and passes it onto Tomcat, the Nginx log might have a timestamp of "2015-10-29T00:37:02+00:00" and Tomcat will have a timestamp of "2015-10-29T00:37:02,106+0000" for the same access. I'm not concerned about the minor differences in formatting, but not having milliseconds (the ",106" part in the Tomcat log) is a problem because it prevents us from correlating the logs correctly.
Is there any way to make Nginx include milliseconds in it's logs?
已采纳解答
原帖链接 · Ed Rowe · CC BY-SA 3.0
Unfortunately, based on reading the source code to nginx, there doesn't seem to be a simple way to do this. You would need to post-process the logs (you could take the output of $msec and turn it into ISO8601 with ms yourself) or patch nginx to add this.
Interestingly a patch was proposed years ago that would have given enough flexibility to make it possible, but I don't think it went anywhere: http://nginx.2469901.n2.nabble.com/PATCH-time-custom-supports-a-custom-log-timestamp-td3505292.html#none
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
