Cha*_*ian 2 customization json nginx access-log openresty
我想将每个请求的 JSON 字符串写入访问日志,以便以后使用它会更容易。
我正在使用 Lapis/Openresty 公开的 print(),但是我想覆盖时间戳、日志级别和其他作为 nginx 日志格式一部分的信息。
我怎样才能覆盖它?
To fill access log with json, you can use something like this in your nginx.conf:
log_format mydef "$json_log";
access_log logs/access.log mydef;
server {
...
set $json_log '';
log_by_lua_block {
local json = require "cjson"
ngx.var.json_log = json.encode({my_json_data = 1})
}
}
Run Code Online (Sandbox Code Playgroud)
If you want to remove the default prefix in nginx error log, it is impossible yet since the format is hardcoded inside nginx's source.
However, you can provide your data in customized format during log_by_lua context to your consumer.
| 归档时间: |
|
| 查看次数: |
1610 次 |
| 最近记录: |