3.6. Logging Cookies
Problem
You want to record all the cookies sent to your server by clients and all the cookies your server asks clients to set in their databases; this can be useful when debugging Web applications that use cookies.
Solution
To log cookies received from the client:
CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i"
CustomLog logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"To log cookie values set and sent by the server to the client:
CustomLog logs/cookies_out.log "%{UNIQUE_ID}e %{Set-Cookie}o"
CustomLog logs/cookies2_out.log "%{UNIQUE_ID}e %{Set-Cookie2}o"In versions before to 2.0.56, using the
%{Set-Cookie}o format effector for debugging is not
recommended if multiple cookies are (or may be) involved. Only the
first one will be recorded in the logfile. See the Discussion text for
an example.
Discussion
Cookie fields tend to be very long and complex, so the previous
statements will create separate files for logging them. The cookie log
entries can be correlated against the client request access log using
the server-set UNIQUE_ID
environment variable (assuming that mod_unique_id is active in the server and
that the activity log format includes the environment variable with a
%{UNIQUE_ID}e format effector).
At the time of this writing, the Cookie and Set-Cookie header fields are most commonly
used. The Cookie2 and corresponding
Set-Cookie2 fields are newer and
have been designed to correct some of the shortcomings in the original specifications, but they haven’t ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access