1

I am new in log4j. As I read on internet, child logger inherit parent logger settings. Usually examples are given are for two classes in same package. But what if the classes will be in different packages? For example

import com.foo.Bar;

public class MyApp{
   static Logger logger = Logger.getLogger(MyApp.class);

   public static void main(String[] args) {
      BasicConfigurator.configure(); // default logging level is debug
      Bar bar = new Bar();
      bar.doIt();
   }
}

and the second class in different package

package mypackage;
import org.apache.log4j.Logger;

public class Bar {
   static Logger logger = Logger.getLogger(Bar.class);

public void doIt() {
     logger.debug("Did it again!");
   }
 }

So what will be the level of logger in class Bar?

swiedenfeld
  • 298
  • 2
  • 14
dev dev
  • 61
  • 1
  • 7

1 Answers1

0

MyApp is in default package. Note that it is not recommended to use default package as has been answered in this question.

I think it is impossible to define a custom <logger> for the default package, so it must be <root> applied.

Unless you define a custom <logger> for mypackage.Bar, <root>also applies for that class.

Apart from the fact that they both may be ruled by <root>, MyApp and Bar are unrelated when it comes to log configuration.

Community
  • 1
  • 1
swiedenfeld
  • 298
  • 2
  • 14