With Tomcat, it is possible to dump a pile of interesting information to the a logfile by configuring the appropriate valve.
For example:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="localhost."
suffix=".txt"
pattern='%s %b %I %{myname}s'
resolveHosts="false"/>
means:
- %s - output HTTP status code of the response
- %b - output Bytes sent,excluding HTTP headers, or '-' if zero
- %I - threadId
and %{myname}s meaning output the value of the attribute myname stored on the session.
All good. If I have a hashmap stored on my session, I can output by doing something like:
%{mymap}s
See http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html for more info.
But, I want to just output a value for a specific key, not the entire map. I have tried:
%{mymap.myatt}s
But this does not work. Any ideas how to do this?
Looking in the source for
AccessLogValve
, search for the StringSessionAttributeElement
. This is what the value is doing to translate your%{mymap}s
to a string, and it does not look like you can drill down into the map.You could extend this class and override the
createAccessLogElement
method to add in another handler for a different pattern (lets say%{mymap.myatt}m
), and then handle the logic in a similar fashion to theSessionAttributeElement
class, but split the header into the session attribute name and map key.