apache httpd日志格式不支持strftime格式

agyaoht7  于 2022-11-25  发布在  Apache
关注(0)|答案(2)|浏览(132)

我需要一个8601时间戳在我的httpd日志,但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,我也会得到上面的完整日期字符串。
==〉"Wed Dec 27 19:24:50 2017"
有趣是,
==〉"2017-12-27 19:24:22.443786"
所以他们的自定义令牌似乎工作。所有我想要的是一个ISO 8601友好邮票!
有什么主意吗?here's a runnable example with docker.谢谢!
strftime引用:https://linux.die.net/man/3/strftime

yyhrrdl8

yyhrrdl81#

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"
4xy9mtcn

4xy9mtcn2#

这是一个老问题,但我想我会在这里放一个正确的答案,以防有人像我一样偶然发现它。
ErrorLogFormat和LogFormat由不同的模块提供,并且具有不同的格式字符串。ErrorLogFormat仅支持非常有限的时间格式。
错误日志格式:https://httpd.apache.org/docs/current/mod/core.html#errorlogformat
日志格式:https://httpd.apache.org/docs/current/mod/mod_log_config.html#formats

相关问题