NGINX Openresty - 访问日志格式 - 对齐输出

时间:2015-03-06 21:24:35

标签: nginx openresty

我在我的项目中使用NGINX Openresty(版本1.4.3.4),我想知道我是否可以使访问日志对齐。

来自:

[06/Mar/2015:21:20:11 +0000] [0.028] [200] [54.162.222.95] ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.020] [200] [108.177.223.182] ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.022] [204] [208.43.79.196] ["POST /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.018] [204] [173.192.139.113]  ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.019] [200] [54.152.215.46]  ["GET /XXX"]

看起来像这样

[06/Mar/2015:21:20:11 +0000] [0.028] [200] [54.162.222.95]   ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.020] [200] [108.177.223.182] ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.022] [204] [208.43.79.196]   ["POST /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.018] [204] [173.192.139.113] ["GET /XXX"]
[06/Mar/2015:21:20:11 +0000] [0.019] [200] [54.152.215.46]   ["GET /XXX"]

目前我的设置是:

log_format normal '[$time_local] [$request_time] [$status] [$http_x_forwarded_for] ["$request"]';

感谢。

1 个答案:

答案 0 :(得分:1)

您无法将日志与log_format对齐到您想要的内容。

您可以使用log_by_lua创建自己的日志,使其达到您想要的任何格式。