Skip to content

how to logging response body into access.log #7297

Answered by soulbird
gracekk asked this question in Q&A
Discussion options

You must be logged in to vote

There is no built-in variable support to get the response body, if your response body size is unpredictable, I suggest you don't log it, it will make your log size very large.
But, If you insist on doing this, you can use the following way:
1、Set a var like:

set $resp_body '';

2、set log format:

access_log_format $resp_body;

3、Customize a plugin to assign a value to $resp_bdoy:

function _M.body_filter(conf, ctx)
    local body = core.response.hold_body_chunk(ctx)
    ctx.var.resp_body = body
    .............
end

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@gracekk
Comment options

Answer selected by monkeyDluffy6017
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants