apache httpd LogFormat不遵循strftime格式 [英] apache httpd LogFormat not honoring strftime format
问题描述
我的httpd日志中需要8601时间戳记,但是httpd似乎不遵守其时间格式约定.我正在使用Apache httpd 2.4.6.
i need a 8601 timestamp in my httpd logs, but httpd appears to not be honoring its time formatting contract. i'm using apache httpd 2.4.6.
我有一个日志记录conf,如下所示:
i have a logging conf as follows:
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布局(是的,也许不能完全逃脱).
as you can see, this is a compact json layout (yes, perhaps not perfectly escaped).
观察时间戳字段.当我登录时,一条日志消息看起来像这样:
observe the timestamp fields. when i log, a log message looks like this:
{"level": "notice", ... ,"timestamp":"Wed Dec 27 19:16:05 2017"}
httpd不遵循指定的时间戳或正确格式化我的时间戳.docs https://httpd.apache.org/docs/current/mod/mod_log_config.html#formats 建议这样做.
httpd doesn't honor or properly format my timestamp as specified. the docs https://httpd.apache.org/docs/current/mod/mod_log_config.html#formats suggest this should work.
即使我将其简化为一种单一格式,例如%{%T} t
,我也会从上面获得完整的日期字符串.
Even I simplify it to just a single format, like %{%T}t
, i get the full datestring per above.
%{%T} t
==> "2017年12月27日星期三19:24:50"
有趣的是,
%{%usec_frac} t
==> "2017-12-27 19:24:22.443786"
,因此他们的自定义标记似乎有效.我想要的只是一张ISO 8601友好邮票!
so their custom tokens seem to work. all i want is an iso 8601 friendly stamp!
有什么想法吗?这是docker的可运行示例.谢谢!
any ideas? here's a runnable example with docker. thanks!
strftime ref: https://linux.die.net/man/3/strftime
strftime ref: https://linux.die.net/man/3/strftime
推荐答案
LogFormat "%h %l %u %{%FT%T%z}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
发射
127.0.0.1 - - 2021-03-09T19:07:07+0000 "GET / HTTP/1.1" 200 28 "-" "curl/7.61.1"
这篇关于apache httpd LogFormat不遵循strftime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!