Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j and weblogic: duplicate log messages

I use log4j for logging in my project. Here is it's sample 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 on each next logger call it duplicates log messages (I mean on first call there is only 1 message, on second call there are 2 same messages, then there are 3 of them and so on). It seems that each time new logger's instance is created and used with all old instances.
How to avoid this problem? Thanks.

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

like image 609
kardanov Avatar asked Aug 17 '11 14:08

kardanov


People also ask

Does Oracle WebLogic Server use Log4j?

WebLogic logging services use an implementation based on the Java Logging APIs, by default. Using the LogMBean. isLog4jLoggingEnabled attribute, you can direct the logging services to use Log4j instead. In the Administration Console, you can specify Log4j or keep the default Java Logging implementation.

How to set log level in WebLogic Server?

Carry out the following steps to change the log level for debugging: Access the Administration Console by pointing your web browser to http://adminhost.domain.local:7001/console . Click on the Lock & Edit button to start a new edit session. Expand the Environment tree on the left, and then click on the Servers link.


1 Answers

Make the logger static

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

The key here is to create a Logger for each class, and not for each instance.

like image 164
Shawn Avatar answered Oct 05 '22 23:10

Shawn