Log4j and weblogic: duplicate log messages

I use log4j to enter my project. Here is an example setup:

public class MyClass {
  private final Logger logger = Logger.getLogger(MyClass.class);

  public MyClass() {
    BasicConfigurator.configure();
    Logger.getLogger(MyClass.class).setLevel(Level.INFO);
  }

  ...

}

The problem is that with each next call to the log it duplicates the log messages (I mean that on the first call there is only one message, on the second call there are two identical messages, then there are 3 of them, etc.). It seems that every time a new journal instance is created and used with all old instances.
How to avoid this problem? Thank.

SCP Tried to make it static, but it still doesn't work. I still get some log messages. Any ideas? Probably some specific Weblogic stuff?

+5
4

static

private static final Logger logger = Logger.getLogger(MyClass.class);

Logger , .

+4

false config.

    Logger.getLogger(MyClass.class).setAdditivity(false);

, log4j.xml

<logger name="com.stackoverflow.answers.gnat" additivity="false">
    <!-- note additivity value set above -->
    <level value="INFO"/>
    <appender-ref ref="knowledge"/>
    <appender-ref ref="reputation"/>
</logger>
+2

Logger , , , log4j -D JVM, , . , - .

log4j - .

-?

, WebLogic Server : http://download.oracle.com/docs/cd/E12840_01/wls/docs103/logging/logging_services.html

, .

+1

BasicConfurator.configure(). java, WebLogic.

BasicConfigurator.configure() beforeTest() beforeClass(), .

@BeforeClass
public static void beforeClass() {
  BasicConfigurator.configure();
  GeoLogger.setLogLevel(Level.INFO);
}

@Before
public void beforeTest() {
  //BasicConfigurator.configure();
}

, .

0

All Articles