use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class InMemoryAppenderTest method assertMessage.
private void assertMessage(final String string, final InMemoryAppender app, final String header) {
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"TestLogger").setLoggerFqcn(//
InMemoryAppenderTest.class.getName()).setLevel(//
Level.INFO).setMessage(//
new SimpleMessage("Test")).build();
app.start();
assertTrue("Appender did not start", app.isStarted());
app.append(event);
app.append(event);
final String msg = app.toString();
assertNotNull("No message", msg);
final String expectedHeader = header == null ? "" : header;
final String expected = expectedHeader + "Test" + Strings.LINE_SEPARATOR + "Test" + Strings.LINE_SEPARATOR;
assertTrue("Incorrect message: " + msg, msg.equals(expected));
app.stop();
assertFalse("Appender did not stop", app.isStarted());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class Log4jLogEventTest method testTimestampGeneratedByClock.
@Test
public void testTimestampGeneratedByClock() {
final LogEvent evt = Log4jLogEvent.newBuilder().build();
assertEquals(FixedTimeClock.FIXED_TIME, evt.getTimeMillis());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class Log4jLogEventTest method testBuilderCorrectlyCopiesAllEventAttributes.
@SuppressWarnings("deprecation")
@Test
public void testBuilderCorrectlyCopiesAllEventAttributes() {
final Map<String, String> contextMap = new HashMap<>();
contextMap.put("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
final Message message = new SimpleMessage("foo");
final StackTraceElement stackTraceElement = new StackTraceElement("A", "B", "file", 123);
final String fqcn = "qualified";
final String name = "Ceci n'est pas une pipe";
final String threadName = "threadName";
final Log4jLogEvent event = //
Log4jLogEvent.newBuilder().setContextMap(//
contextMap).setContextStack(//
contextStack).setEndOfBatch(//
true).setIncludeLocation(//
true).setLevel(//
Level.FATAL).setLoggerFqcn(//
fqcn).setLoggerName(//
name).setMarker(//
marker).setMessage(//
message).setNanoTime(//
1234567890L).setSource(//
stackTraceElement).setThreadName(//
threadName).setThrown(//
exception).setTimeMillis(987654321L).build();
assertEquals(contextMap, event.getContextMap());
assertSame(contextStack, event.getContextStack());
assertEquals(true, event.isEndOfBatch());
assertEquals(true, event.isIncludeLocation());
assertSame(Level.FATAL, event.getLevel());
assertSame(fqcn, event.getLoggerFqcn());
assertSame(name, event.getLoggerName());
assertSame(marker, event.getMarker());
assertSame(message, event.getMessage());
assertEquals(1234567890L, event.getNanoTime());
assertSame(stackTraceElement, event.getSource());
assertSame(threadName, event.getThreadName());
assertSame(exception, event.getThrown());
assertEquals(987654321L, event.getTimeMillis());
final LogEvent event2 = new Log4jLogEvent.Builder(event).build();
assertEquals("copy constructor builder", event2, event);
assertEquals("same hashCode", event2.hashCode(), event.hashCode());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class Log4jLogEventTest method testToImmutableSame.
@Test
public void testToImmutableSame() {
final LogEvent logEvent = new Log4jLogEvent();
Assert.assertSame(logEvent, logEvent.toImmutable());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MutableLogEventTest method testToImmutable.
@Test
public void testToImmutable() {
final LogEvent logEvent = new MutableLogEvent();
Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
Aggregations