问题背景,Apache2里面日志输出,关于时间这一块,看着难受,所以有了如下需求,修改日志里面的时间格式

案例日志

127.0.0.1 - - [31/Oct/2024:19:20:34 +0800] "GET /index.php/vod/search/actor/Ximena+del+Solar.html HTTP/1.1" 200 4233 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.69 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

 执行

 nano /etc/apache2/apache2.conf

 修改成

LogFormat "%v:%p %h %l %u %{%Y%m%d_%H:%M:%S %z}t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %{%Y%m%d_%H:%M:%S %z}t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %{%Y%m%d_%H:%M:%S %z}t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

配置的重点是%{%Y%m%d_%H:%M:%S %z}t 

 

最终日志输出

127.0.0.1 - - 20241031_19:40:19 +0800 "GET /index.php/vod/detail/id/38904.html HTTP/1.1" 200 7875 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.69 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部