Skip to content

can't print the response header Set-Cookie in log #845

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

Closed
tjliupeng opened this issue Aug 22, 2016 · 4 comments
Closed

can't print the response header Set-Cookie in log #845

tjliupeng opened this issue Aug 22, 2016 · 4 comments

Comments

@tjliupeng
Copy link

Hi,

I try to print the response header Set-Cookie to log by:

header_filter_by_lua_block {
ngx.log(ngx.WARN, "Set-Cookie %s", ngx.resp.get_headers()['Set-Cookie'] or "None")
}

But I get nothing in access.log or error.log.

Thanks

@detailyang
Copy link
Contributor

detailyang commented Aug 22, 2016

check the docs

Syntax: error_log file [level];
Default:    
error_log logs/error.log error;
Context:    main, http, mail, stream, server, location

the log level can be debug, info, notice, warn, error, crit, alert, or emerg. And level is error at default, your are using ngx.WARN to logging so it will be ignored. you can use ngx.ERR or set error_log level to warn

@tjliupeng
Copy link
Author

tjliupeng commented Aug 23, 2016

Thanks. I change to ngx.ERR and something is printed in error.log. But it fail to get the Set-Cookie header as follow. If I change Set-Cookie to Connection, it can print the value of Connection. Seems 'or None' does not work.

2016/08/23 14:05:58 [error] 22020#22020: 1 failed to run header_filter_by_lua: header_filter_by_lua:2: bad argument #2 to 'log' (expected table to have __tostring metamethod)
stack traceback:
[C]: in function 'log'
header_filter_by_lua:2: in function <header_filter_by_lua:1> while reading response header from upstream, client: 15.107.4.15, server: 16.165.217.31, request: "POST /SM/ui HTTP/1.1", upstream: "http://15.107.4.15:13080/SM/ui", host: "16.165.217.31"
2016/08/23 14:05:58 [error] 22020#22020: 3 failed to run header_filter_by_lua: header_filter_by_lua:2: bad argument #2 to 'log' (expected table to have __tostring metamethod)
stack traceback:
[C]: in function 'log'
header_filter_by_lua:2: in function <header_filter_by_lua:1> while reading response header from upstream, client: 15.107.4.15, server: 16.165.217.31, request: "POST /SM/ui HTTP/1.1", upstream: "http://15.107.4.15:13081/SM/ui", host: "16.165.217.31"

@detailyang
Copy link
Contributor

the error as the following:

header_filter_by_lua:2: bad argument #2 to 'log' (expected table to have __tostring metamethod)

it means your ngx.resp.get_headers()['Set-Cookie'] argument is table . you cannot log table directly unless you have __tostring metamethod.

I guess you upstream return more than set-cookie header. you can check this docs carefully

@tjliupeng
Copy link
Author

@detailyang , you are right. Thanks.

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

No branches or pull requests

2 participants