Search in sources :

Example 1 with JULBridgeHandler

use of com.twitter.common.logging.julbridge.JULBridgeHandler in project commons by twitter.

the class JULBridgeHandlerTest method checkGetLoggerReturnsLoggerWithSameName.

@Test
public void checkGetLoggerReturnsLoggerWithSameName() {
    LogRecord record = new LogRecord(Level.FINEST, "test message");
    record.setLoggerName("test.checkGetLogger");
    assertThat(new JULBridgeHandler().getLogger(record).getName(), is("test.checkGetLogger"));
}
Also used : JULBridgeHandler(com.twitter.common.logging.julbridge.JULBridgeHandler) LogRecord(java.util.logging.LogRecord) Test(org.junit.Test)

Example 2 with JULBridgeHandler

use of com.twitter.common.logging.julbridge.JULBridgeHandler in project commons by twitter.

the class JULBridgeHandlerTest method checkToLoggingEvent.

@Test
public void checkToLoggingEvent() {
    LogRecord record = new LogRecord(Level.FINEST, "test is {0}");
    record.setParameters(new Object[] { "successful" });
    record.setThreadID(42);
    Throwable t = new Throwable();
    record.setThrown(t);
    // source class and method names are usually inferred, but because there's no JUL in the stack
    // frame, it won't work as expected.
    record.setSourceClassName(getClass().getName());
    record.setSourceMethodName("checkToLoggingEvent");
    Logger log4jLogger = new JULBridgeHandler().getLogger(record);
    org.apache.log4j.Level log4jLevel = JULBridgeLevelConverter.toLog4jLevel(Level.FINEST);
    LoggingEvent event = JULBridgeHandler.toLoggingEvent(record, log4jLogger, log4jLevel, false);
    assertThat(event.getLogger(), is((Category) log4jLogger));
    assertThat(event.getLevel(), is(log4jLevel));
    assertThat(event.getMessage(), is((Object) "test is successful"));
    assertThat(event.getThreadName(), is("42"));
    assertThat(event.getTimeStamp(), is(record.getMillis()));
    assertThat(event.getThrowableInformation().getThrowable(), is(sameInstance(t)));
    LocationInfo info = event.getLocationInformation();
    assertThat(info.getClassName(), is(getClass().getName()));
    assertThat(info.getMethodName(), is("checkToLoggingEvent"));
}
Also used : JULBridgeHandler(com.twitter.common.logging.julbridge.JULBridgeHandler) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Category(org.apache.log4j.Category) LogRecord(java.util.logging.LogRecord) Logger(org.apache.log4j.Logger) LocationInfo(org.apache.log4j.spi.LocationInfo) Test(org.junit.Test)

Aggregations

JULBridgeHandler (com.twitter.common.logging.julbridge.JULBridgeHandler)2 LogRecord (java.util.logging.LogRecord)2 Test (org.junit.Test)2 Category (org.apache.log4j.Category)1 Logger (org.apache.log4j.Logger)1 LocationInfo (org.apache.log4j.spi.LocationInfo)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1