logging session ID in each entry
843844May 30 2007 — edited May 30 2007Hi all,
I'm trying to log the session ID in each log entry, so that I'm able to see which log entry belonged to which session when analysing the log file later.
I'm using log4j and I think the right way to do stuff like this is to push the session ID to the NDC (nested diagnostic context, see http://logging.apache.org/log4j/docs/api/org/apache/log4j/NDC.html).
Now I'm having trouble to find the right place where to push this ID to the NDC and when to remove it again. The NDC is thread based, but I'm not sure how this fits into the JSF model.
I tried to use PhaseListeners, one before the RESTORE_VIEW (NDC.push()), and one after RENDER_RESPONSE (NDC.remove()), but this leads to multiple session IDs being in the NDC after a few requests.
Any idea how to fix this cleanly? Or any other approach?
Thanks a lot,
Gunnar