开发者

Java: How to log any time something put in session?

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


You could install a HttpSessionAttributeListener in web.xml.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜