tags:

views:

76

answers:

2

I am evaluating a JSF Java project with 100 or so screens and would like to be able to log every time something is put in to the HTTP session along with who's calling the method on the session object and what the paramters are, to make it easier for me to know what's going into session when I click through the site.

So I want a log like:

12:00:00pm HTTPSession.setAttribute() called by z.y.x.MyClass, params: z.y.x.MySecondClass, z.y.x.MyThirdClass)

Does anyone have a suggestion how to do this? I'm looking for some kind of log4j (they use log4j) configuration that would do this type of thing so that I dont touch any code

+4  A: 

You could install a HttpSessionAttributeListener in web.xml.

Thilo
A: 

In addition to HttpSessionAttributeListener, as noted by Thilo, you can use log4j MDC to keep track of all subsequent log statements in this session. That, of course, will only work if the listener gets called by the session thread because MDC context is kept per thread.

Dima
There is no such thing as "session thread" in JSP/Servlet.
BalusC
Anything processed in any program, be it JSP or Servlet, is done by some thread. A servlet is called by the container when it processes the http request. I meant this particular thread. As far as I know it might be the same thread living for the life span of a session, or it might be another thread taken from the pool for the subsequent requests. This is why you should be careful with the context. But still, as long as request propagates through the layer, the MDC could be very useful to log the context of this particular thread.
Dima