Seam log4j credential logs
- by Marc
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?