apache httpd LogFormat 不支持 strftime 格式

标签 apache httpd.conf strftime

我的 httpd 日志中需要一个 8601 时间戳,但 httpd 似乎没有遵守其时间格式契约(Contract)。我正在使用 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"
所以他们的自定义 token 似乎有效。我只想要一张 iso 8601 友好邮票!

有任何想法吗? here's a runnable example with docker .谢谢!

strftime 引用: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 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47997641/

相关文章:

php - mod_auth_openidc 如何访问用于 PHP 的用户变量

linux - httpd 没有按预期读取conf/httpd.conf 中的文档根目录

python - 如何获取过去7小时的strftime?

c - 在 C 中比较没有日期的时间(小时和秒)的最佳方法?

apache - 如何使用 apache mod_proxy_balancer 基于 session 标识符启用粘性负载平衡

ruby-on-rails - Rails 将多列查询转换为 strftime ("%H") ... NoMethodError : undefined method `strftime'

linux - 为什么 Ubuntu 上的 Apache 对于未知文件扩展名显示为空白...即使使用 DefaultType text/plain 也是如此?

android - honeycomb中执行Http post报错

java - 如何使用 Apache POI 从 Excel 文件中获取列?

php - 使用 htaccess 重定向到 php 脚本