use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class LoggerTest method testTraceWithException.
/**
* Tests logger.trace(Object, Exception).
*/
@Test
public void testTraceWithException() {
final ListAppender appender = new ListAppender("List");
appender.start();
final Logger root = Logger.getRootLogger();
try {
root.getLogger().addAppender(appender);
root.setLevel(Level.INFO);
final Logger tracer = Logger.getLogger("com.example.Tracer");
tracer.setLevel(Level.TRACE);
final NullPointerException ex = new NullPointerException();
tracer.trace("Message 1", ex);
root.trace("Discarded Message", ex);
root.trace("Discarded Message", ex);
final List<LogEvent> msgs = appender.getEvents();
assertEquals(1, msgs.size());
final LogEvent event = msgs.get(0);
assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
assertEquals("Message 1", event.getMessage().getFormattedMessage());
appender.stop();
} finally {
root.getLogger().removeAppender(appender);
}
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class LogEventEntityTest method testToImmutable_AbstractLogEventWrapperEntity.
@Test
public void testToImmutable_AbstractLogEventWrapperEntity() {
final LogEvent logEvent = new AbstractLogEventWrapperEntity() {
private static final long serialVersionUID = 1L;
@Override
public Map<String, String> getContextMap() {
return null;
}
@Override
public ContextStack getContextStack() {
return null;
}
@Override
public Level getLevel() {
return null;
}
@Override
public String getLoggerFqcn() {
return null;
}
@Override
public String getLoggerName() {
return null;
}
@Override
public Marker getMarker() {
return null;
}
@Override
public Message getMessage() {
return null;
}
@Override
public long getNanoTime() {
return 0;
}
@Override
public StackTraceElement getSource() {
return null;
}
@Override
public long getThreadId() {
return 0;
}
@Override
public String getThreadName() {
return null;
}
@Override
public int getThreadPriority() {
return 0;
}
@Override
public Throwable getThrown() {
return null;
}
@Override
public ThrowableProxy getThrownProxy() {
return null;
}
@Override
public long getTimeMillis() {
return 0;
}
};
Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class LogEventEntityTest method testToImmutable_TestBaseEntity.
@Test
public void testToImmutable_TestBaseEntity() {
final LogEvent logEvent = new TestBaseEntity();
Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class AbstractDatabaseAppenderTest method testAppend.
@Test
public void testAppend() {
setUp("name");
given(manager.commitAndClose()).willReturn(true);
final LogEvent event1 = mock(LogEvent.class);
final LogEvent event2 = mock(LogEvent.class);
appender.append(event1);
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event1));
then(manager).should().commitAndClose();
reset(manager);
appender.append(event2);
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event2));
then(manager).should().commitAndClose();
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class AbstractDatabaseManagerTest method testBuffering01.
@Test
public void testBuffering01() throws Exception {
setUp("name", 0);
final LogEvent event1 = mock(LogEvent.class);
final LogEvent event2 = mock(LogEvent.class);
final LogEvent event3 = mock(LogEvent.class);
manager.startup();
then(manager).should().startupInternal();
reset(manager);
manager.write(event1);
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event1));
then(manager).should().commitAndClose();
reset(manager);
manager.write(event2);
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event2));
then(manager).should().commitAndClose();
reset(manager);
manager.write(event3);
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event3));
then(manager).should().commitAndClose();
then(manager).shouldHaveNoMoreInteractions();
}
Aggregations