Hi,
I encountered a synchronization issue with log4j 1.2.15 : if two threads
write into 2 loggers that are plugged into 2 FileAppenders, the two
resulting files are mixed up...
Here is the code of my simple test. The problem is that at the end of
the execution, the file "log1" contains some lines "MESSAGE FOR
logger2", and conversely.
public class Log4JTest {
public static void main(String[] args) {
System.out.println("Log4JTest.main()");
// TODO Auto-generated method stub
Logger l1 = Logger.getLogger("logger1");
l1.setLevel(Level.INFO);
Logger l2 = Logger.getLogger("logger2");
l2.setLevel(Level.INFO);
try {
FileAppender fa1 = new
FileAppender(Log4JTaskLogs.DEFAULT_LOG_LAYOUT,
"/user/cdelbe/home/tmp/log1",false);
l1.addAppender(fa1);
FileAppender fa2 = new
FileAppender(Log4JTaskLogs.DEFAULT_LOG_LAYOUT,
"/user/cdelbe/home/tmp/log2",false);
l2.addAppender(fa2);
} catch (IOException e) {
e.printStackTrace();
}
Thread t1 = new Thread(new Writer("logger1"));
Thread t2 = new Thread(new Writer("logger2"));
t1.start();
t2.start();
}
static class Writer implements Runnable {
private String loggerName;
Writer(String loggerName) {
this.loggerName = loggerName;
}
public void run() {
Logger l=Logger.getLogger(loggerName);
for (int i=0;i<10000;i++){
l.info("MESSAGE FOR " + loggerName);
}
}
}
}
Thank you in advance for your help !
Christian.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]