Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: I want to add the result data of the request response to the access log #5037

Closed
ly-hash opened this issue Sep 10, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@ly-hash
Copy link

ly-hash commented Sep 10, 2021

Issue description

I want to add the result data of the request response to the access log. Now it seems that only status is supported. What should I do? In addition, I want to return the response result of JSON. For the HTML returned now, the response code is also specified, such as 404,500. The return part of the code can be customized,thank you

Environment

  • apisix version (cmd: apisix version): 2.9
  • OS (cmd: uname -a): centOS7
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): 1.19.9.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • luarocks version, if the issue is about installation (cmd: luarocks --version):
@tokers
Copy link
Contributor

tokers commented Sep 11, 2021

You may have to collect the response body by concatenating them in the body_filter phase, you may serialize them into a Nginx variable and print it in the access log, since you need another Nginx variable, you may have to modify the apisix/cli/ngx_tpl.lua to add it (as currently, APISIX doesn't support to configure custom Nginx variables in config.yaml).

@tzssangglass
Copy link
Member

It seems that there are some about this feature.

For the response body, it can be logged in the log files, also in plugins such as kafka-logger, and pushed to the log server.

@ly-hash
Copy link
Author

ly-hash commented Sep 13, 2021

@tokers,thank you very much
If I need to customize the result of the returned response, for example, instead of returning 404 or 500 information, it is a JSON structure, how should I modify it

@ly-hash
Copy link
Author

ly-hash commented Sep 13, 2021

@tzssangglass,I think you're right. It may be more convenient for users to make it into a plug-in

@tzssangglass
Copy link
Member

I find it difficult to log the response body in the log file(access.log, error.log), which involves the log_format directive.

But allowing it in a logging plugin like kafka-logger is possible.

@aikin-vip
Copy link
Contributor

need this feature too!!!

@zcstack
Copy link

zcstack commented Sep 17, 2021

It is recommended that developers support the response body in existing Logger plug-ins!

@spacewander spacewander added the enhancement New feature or request label Sep 24, 2021
@spacewander
Copy link
Member

Solved by #5550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants