feat: file logger plugin support response body in variable#8711
Conversation
| @@ -0,0 +1,124 @@ | |||
| # | |||
There was a problem hiding this comment.
Could we move these tests under https://github.com/apache/apisix/blob/master/t/plugin/file-logger2.t? That file is still small and doesn't have special setup.
There was a problem hiding this comment.
Move to file-logger2
| metadata_schema = metadata_schema | ||
| } | ||
|
|
||
| core.ctx.register_var("resp_body", function(ctx) |
There was a problem hiding this comment.
Would be better to put it in https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua so other loggers can use it too.
There was a problem hiding this comment.
I don't think this var should be put into the ctx.lua file. Because the value of resp_body comes from ctx.resp_body, which is set by file-logger when include_resp_body = true.
There was a problem hiding this comment.
Not only one logger plugin will support recording the response body. file-logger.lua is not an appropriate place.
| | ---- | ------ | -------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | path | string | True | Log file path. | | ||
| | include_resp_body | boolean | False | When set to `true` includes the response body in the log file. | | ||
| | include_resp_body | boolean | False | When set to `true` includes the response body in the log file. If format is set, you can use the variable $resp_body to get the response body. | |
There was a problem hiding this comment.
Would be better to put it in https://github.com/apache/apisix/blob/master/docs/en/latest/apisix-variable.md, instead of modifying each logger's doc.
Note that we need to mean that this variable is only for logger and requires the logger to have a special configuration.
| route_name = true, | ||
| service_id = true, | ||
| service_name = true, | ||
| resp_body = function(ctx) |
| service_id = true, | ||
| service_name = true, | ||
| resp_body = function(ctx) | ||
| -- only work when file-logger set include_resp_body = true |
| | service_name | core | Name of Service. | | | ||
| | redis_cmd_line | Redis | The content of Redis command. | | | ||
| | rpc_time | xRPC | Time spent at the rpc request level. | | | ||
| | resp_body | core | This variable is only for logger and requires the logger to have a special configuration. | | |
There was a problem hiding this comment.
Which special configuration? I'm afraid that such a description is not useful for users to use this variable.
| route_id = true, | ||
| route_name = true, | ||
| service_id = true, | ||
| service_name = true, |
| | service_name | core | APISIX 服务的名称。 | | | ||
| | redis_cmd_line | Redis | Redis 命令的内容。 | | | ||
| | rpc_time | xRPC | 在 RPC 请求级别所花费的时间。 | | | ||
| | resp_body | core | 此变量仅用于 Logger,并要求对应的 Logger 需要具备某些配置。 | | |
There was a problem hiding this comment.
Please put it in alphabetical order
| | service_name | core | Name of Service. | | | ||
| | redis_cmd_line | Redis | The content of Redis command. | | | ||
| | rpc_time | xRPC | Time spent at the rpc request level. | | | ||
| | resp_body | core | This variable is only for logger and requires the logger plugin to have a special configuration like `include_resp_body`. | | |
There was a problem hiding this comment.
We should explain what this variable is, and what decides its value
Co-authored-by: 罗泽轩 <[email protected]>
* upstream/master: docs: change the file name to 'create-ssl.py'.If 'ssl.py' is used as … (apache#8623) feat: Body transformer plugin (apache#8766) fix: mocking plugin panic when response_example contain $ (apache#8810) (apache#8816) feat: file logger plugin support response body in variable (apache#8711) docs(getting-started): rewrite the install section (apache#8807) feat: allow each logger to define custom log format in its conf (apache#8806) fix(etcd): reloaded data may be in res.body.node (apache#8736) fix: fix fetch all service info from consul (apache#8651) docs: fix global-rule.md wrong curl address (apache#8793) feat: stream subsystem support consul service discovery (apache#8696) chore(kafka-logger): support configuration `meta_refresh_interval` parameter (apache#8762) feat: ready to release 2.15.2 (apache#8783)
Description
We need to add a new var resp_body to let the user put it in a log format which let the user use the response in the way there want.
Fixes #8705
Checklist