问题原文
原帖链接 · jamesc · CC BY-SA 3.0
I'm aware of the $msec logging parameter which gives the request time as seconds since Unix epoch with millisecond granularity. However, the format of this includes a period '.' e.g. '1407233265.472' and this is a problem for the import function that I'm using to parse the log files.
Is there a way (log parameter or plugin) that will allow the request time to be recorded in total milliseconds? e.g. '1407233265472'. Am happy to compile nginx as required.
社区高分解答
原帖链接 · Sirk Johannsen · CC BY-SA 3.0
There are 2 ways to achieve this. The first one is dirty and I wont recommend it - it's the fastest way though:
if ($msec ~ "(.*)\.(.*)") {
set $epoch_millis = "$1$2"
}
This is much cleaner but requires lua:
set_by_lua_block $epoch_millis { return string.gsub(ngx.var.msec, "%.", "") }
then just log $epoch_millis
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
