An alternative means would be to use NDC.
So your logging methods would look the same as before:
private static final Logger logger =
Logger.getLogger(TheCurrentClass.class);
if (logger.isInfoEnabed()) {
...
}
But before any logs are created for the current request, identify the
current user of your app, ideally in a Servlet filter or other top level
location.
public void doFilter() {
String username = // get user name from incoming servlet request
NDC.push(username);
try {
chain.doFilter(request, response);
} finally {
// Always clean up user information attached to the current thread
NDC.clear();
}
}
Finally, to make all this setup provide the data you want you will need a
custom Log4J filter that accepts the current LoggingEvent if the value of
NDC.peek() is equal to the specified username that the current log file
represents.
There may be additional work configuring many file appenders, one for each
user - have you thought about just writing the username in every logging
event and then correlating them offline (in a database for example)?
Cheers.
Naresh Sikha
-----Original Message-----
From: James Stauffer [mailto:[EMAIL PROTECTED]
Sent: Monday, April 26, 2004 10:46 AM
To: 'Log4J Users List'
Subject: RE: logging per user
You could do:
Logger log = Logger.getLogger(username);
Log.info("User: " + username);
James Stauffer
-----Original Message-----
From: Srinivas Kotamraju [mailto:[EMAIL PROTECTED]
Sent: Monday, April 26, 2004 12:45 PM
To: [EMAIL PROTECTED]
Subject: logging per user
Hi guys,
I am a newbie to log4j. I quickly looked through log4j and it really looks
great and I amazed by its flexibility. I am having a web application and I
have a bunch of users 20 -25..using it. I would like to be able to have one
log file per user..with an option to configure the users in a properties
file. The logfile will be generated only for the configured users. I have
been looking at NDC..is that the one I should be using?
NDC.clear();
NDC.push(userName);
But how would a separate file created for each user?
Can someone please provide me some examples..
Thanks
---------------------------------
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25�
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]