org.apache.log4j.spi.RootLogger Java Examples

The following examples show how to use org.apache.log4j.spi.RootLogger. 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: ProcessingPartitionTest.java    From common-kafka with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
    properties = new Properties();
    properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "my-group");
    properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, OffsetResetStrategy.EARLIEST.toString().toLowerCase());

    config = new ProcessingConfig(properties);
    topicPartition = new TopicPartition("topic", 1);

    when(consumer.committed(topicPartition)).thenReturn(new OffsetAndMetadata(0L));

    partition = new MockProcessingPartition<>(topicPartition, config, consumer);

    logAppender = new TestLogAppender();
    RootLogger.getRootLogger().addAppender(logAppender);
}
 
Example #4
Source File: WebServer.java    From hadoop-hdfs-fsimage-exporter with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.err.println("Usage: WebServer [-Dlog.level=[WARN|INFO|DEBUG]] <hostname> <port> <yml configuration file>"); // NOSONAR
        System.exit(1);
    }

    RootLogger.getRootLogger().setLevel(Level.toLevel(System.getProperty("log.level"), Level.INFO));

    try (FileInputStream reader = new FileInputStream(args[2])) {
        Config config = new Yaml().loadAs(reader, Config.class);
        new WebServer().configure(config, args[0], Integer.parseInt(args[1]));
    }
}
 
Example #5
Source File: LoggerTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public
void testHierarchy1() {
  Hierarchy h = new Hierarchy(new RootLogger((Level) Level.ERROR));
  Logger a0 = h.getLogger("a");
  assertEquals("a", a0.getName());
  assertNull(a0.getLevel());
  assertSame(Level.ERROR, a0.getEffectiveLevel());

  Logger a1 = h.getLogger("a");
  assertSame(a0, a1);
}
 
Example #6
Source File: DataFormatterTest.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() {
  RootLogger.getRootLogger().setLevel( Level.OFF );
  SimpleDateFormat format = new SimpleDateFormat( SAMPLE_DATE_MASK );
  //add custom seconds
  int seconds = 123456;
  sampleJavaDate = new Date( seconds );
  sampleSqlDate = new java.sql.Date( seconds );
  sampleSqlTimeStamp = new Timestamp( seconds );
  sampleStringDate = format.format( sampleJavaDate );
  expectedDate = format.format( sampleJavaDate );
}
 
Example #7
Source File: ProcessingPartitionTest.java    From common-kafka with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    RootLogger.getRootLogger().removeAppender(logAppender);
}
 
Example #8
Source File: LoggingEventProcessor.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public NoWarningHierarchy() {
    super(new RootLogger(Level.ALL));
}