Seam log4j credential logs

Posted by Marc on Stack Overflow See other posts from Stack Overflow or by Marc
Published on 2010-06-05T21:46:34Z Indexed on 2010/06/05 21:52 UTC
Read the original article Hit count: 231

Filed under:
|
|

In Seam, using log4, I would like to have my info, warn and error always logging the logged in user (if so) name to be logged with whatever the log message is.

Being a consistant thing I do not want to have to grab the logged-in user name, and prefix the message. so I attempted to populate the log4j NDC to have it as a field of the log message. Pushing the user name on successful login:

NDC.push(credentials.getUsername());

Which works, but the NDC is managed per thread, so once another thread processes a request from the same logged in user, the trace of this user name is lost. I was thinking that there should be a common pattern to accomplish this simple task which is attaching each log message to the logged user, using the NDC or not, to know exactly what user triggered what action.

Anyone knows the appropriate way to accomplish this?

© Stack Overflow or respective owner

Related posts about logging

Related posts about log4j