2016-12-27 26 views
1

我是log4j中的新成员。当我在互联网上阅读时,儿童记录器会继承父记录器设置。通常给出的例子是在同一个包中的两个类。但是如果这些课程将采用不同的包装呢?例如不同软件包之间的log4j层次结构

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(); 
    } 
} 

,并在不同的包第二类

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!"); 
    } 
} 

那么什么会记录在Bar一流的水平?

回答

0

MyApp是默认包。请注意,不建议使用此question中回答的默认包。

我认为不可能为默认包定义一个自定义的<logger>,所以它必须应用<root>

除非您为mypackage.Bar定义了自定义<logger>,否则<root>也适用于该类。

除了事实上它们都可能由<root>MyAppBar来统治日志配置。