Wednesday, July 23, 2008

Adding Logger interceptor in Struts

When i had a requirement to add user name and session id to every logger statement for debugging purposes i did not think it would be so easy. I came across sites which suggested adding some extra modules and configurations into the log4j.

But i realized there was a much simpler way which was to modify the thread name appending application specific user name and session id into it. As anyways log4j will print the thread name at every logger statement . Thus with minimal changes my cause was served. I added this functionality into every request by making it as a interceptor and adding it into the basic stack.
I have attached the interceptor code for reference.

Tasks get easy when seen for different perspectives.

 
Free Domain Names @ .co.nr!