I know this is a fairly common request, and I have read the log4j short (free) manual, FAQs, and searched this mailing list's archives for the last few months and haven't found the definitive answer to this question yet:
I run a custom-written server that serves clients, each session lasting up to several days. (Think of it as an instant messenger, although it does more). I currently use my own (custom) logging code to have one logfile per client. I've converted everything else over to log4j, and I'd like to use log4j for this too. Currently, I'm using the following code, which seems to work: private void setLogfile(String filename) { // create one log file for this client logger = Logger.getLogger("users." + filename); appender = new FileAppender(new org.apache.log4j.PatternLayout("[%d %-5p %x] - %m%n"), filename+"2", true); appender.setName(filename); // note: appender is a member variable logger.addAppender(appender); logger.info("Starting logfile: "+filename); } and when the client's session ends, I do: logger.removeAllAppenders(); appender.close(); Is this a decent way to handle this, or is there a cleaner way, perhaps using MDC or NDC? The log4j FAQ or manual hints that there is a way to do it, but I can't find it anywhere. Thanks for your comments, and thanks to the log4j team for a great piece of work! Chris Lamprecht -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>