How to add recently set cookies to nginx's access log

Solution 1:

I found a hacky solution to my problem, but it doesn't solve the problem generally.

nginx lets you pass response header elements into the log file, like Set-Cookie:

log_format foo '$remote_addr "$request" '
               '$cookie_bar set_cookie=$sent_http_set_cookie';

Unfortunately it only outputs the first Set-Cookie command, so I need to make sure my app server always sets the bar cookie first. And with a little regexp I can make sure to grab the cookie set in $sent_http_set_cookie if $cookie_bar isn't set.