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
?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.