【发布时间】:2018-06-08 10:06:17
【问题描述】:
我的 httpd 日志中需要一个 8601 时间戳,但 httpd 似乎没有遵守其时间格式合同。我正在使用 apache httpd 2.4.6。
我有一个如下的日志记录配置:
ErrorLogFormat "{\
\"level\": \"%l\",\
...
\"timestamp\":\"%{%Y-%m-%dT%H:%M:%S%z}t\"\
}"
ErrorLog /dev/stderr
LogLevel info
LogFormat "{\
\"logger\": \"common\",\
...
\"timestamp\":\"%{%Y-%m-%dT%H:%M:%S%z}t\",\
}" combined
CustomLog /dev/stdout combined
如您所见,这是一个紧凑的 json 布局(是的,可能没有完美转义)。
观察时间戳字段。当我登录时,日志消息如下所示:
{"level": "notice", ... ,"timestamp":"Wed Dec 27 19:16:05 2017"}
httpd 没有按照指定的方式尊重或正确格式化我的时间戳。文档https://httpd.apache.org/docs/current/mod/mod_log_config.html#formats 建议这应该可行。
即使我将其简化为单一格式,例如 %{%T}t,我也得到了上面的完整日期字符串。
%{%T}t ==> "Wed Dec 27 19:24:50 2017"
有趣的是,
%{%usec_frac}t ==>"2017-12-27 19:24:22.443786"
所以他们的自定义令牌似乎有效。我想要的只是一张符合 ISO 8601 标准的邮票!
有什么想法吗? here's a runnable example with docker。谢谢!
strftime 参考:https://linux.die.net/man/3/strftime
【问题讨论】:
标签: apache httpd.conf strftime