duplicate lines in java applet when using log4j -


i'm trying use log4j in applet, every time refresh page in browser (to restart applet) duplicated lines of output in java console. number of times output duplicated increases after each refresh.

this code reproduces effect:

public class helloworldapplet extends japplet {     static logger logger = logger.getlogger(helloworldapplet.class);     public void init() {         basicconfigurator.configure();         logger.info("hello log4j");         system.out.println("hello system.out");     } } 

and output i'm seeing:

0 [thread applet-helloworldapplet.class-26] info helloworldapplet  - hello log4j hello system.out <refresh> 1987 [thread applet-helloworldapplet.class-27] info helloworldapplet  - hello log4j 1987 [thread applet-helloworldapplet.class-27] info helloworldapplet  - hello log4j hello system.out <again> 3156 [thread applet-helloworldapplet.class-28] info helloworldapplet  - hello log4j 3156 [thread applet-helloworldapplet.class-28] info helloworldapplet  - hello log4j 3156 [thread applet-helloworldapplet.class-28] info helloworldapplet  - hello log4j hello system.out 

clearing classloader cache fixes it, , know need clear classloader cache reload applet, want restart it, when debugging. understand:

  1. why happening?
  2. is there way prevent it?

thanks!

from javadocs basicconfigurator:

public static void configure()

add consoleappender uses patternlayout using patternlayout.ttcc_conversion_pattern , prints system.out root category.

so you're adding new appender each time applet initialized. try calling resetconfiguration() first.


Comments