org.apache.log4j.Hierarchy Java Examples

The following examples show how to use org.apache.log4j.Hierarchy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Log4jTest.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testIndependentSpaceLog4j() {
    LoggerRepository repo1 = new Hierarchy(new RootLogger((Level) Level.DEBUG));
    URL url1 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log-conf.xml");
    OptionConverter.selectAndConfigure(url1, null, repo1);
    Logger logger1 = repo1.getLogger("com.foo.Bar");
    Assert.assertNotNull(logger1);

    //log4j logger 2

    LoggerRepository repo2 = new Hierarchy(new RootLogger((Level) Level.DEBUG));
    URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log4j_b.xml");
    OptionConverter.selectAndConfigure(url2, null, repo2);
    Logger logger2 = repo1.getLogger("com.foo.Bar2");
    Assert.assertNotNull(logger2);

    Assert.assertNotSame(logger1, logger2);
}
 
Example #2
Source File: Log4jTest.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalProperties() throws NoSuchFieldException, IllegalAccessException {

    LoggerRepository repo2 = new Hierarchy(new RootLogger((Level) Level.DEBUG));
    URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log4j_b.xml");
    DOMConfigurator domConfigurator = new DOMConfigurator();

    Field field = DOMConfigurator.class.getDeclaredField("props");
    field.setAccessible(true);
    Properties props = new Properties();
    field.set(domConfigurator, props);
    props.put("hello", "defaultb");

    domConfigurator.doConfigure(url2, repo2);

    Logger logger2 = repo2.getLogger("com.foo.Bar3");
    Assert.assertTrue(logger2.getAllAppenders().hasMoreElements());

}
 
Example #3
Source File: Log4jBackendLoggerTest.java    From flogger with Apache License 2.0 4 votes vote down vote up
private void removeCachedLoggers() {
  ((Hierarchy) LogManager.getLoggerRepository()).clear();
}