use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class YamlLayoutTest method testLayoutLoggerName.
@Test
public void testLayoutLoggerName() throws Exception {
final AbstractJacksonLayout layout = YamlLayout.newBuilder().setLocationInfo(false).setProperties(false).setIncludeStacktrace(true).setCharset(StandardCharsets.UTF_8).build();
final Log4jLogEvent expected = //
Log4jLogEvent.newBuilder().setLoggerName(//
"a.B").setLoggerFqcn(//
"f.q.c.n").setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("M")).setThreadName(//
"threadName").setTimeMillis(1).build();
final String str = layout.toSerializable(expected);
assertThat(str, containsString("loggerName: \"a.B\""));
final Log4jLogEvent actual = new Log4jYamlObjectMapper(false, true, false).readValue(str, Log4jLogEvent.class);
assertEquals(expected.getLoggerName(), actual.getLoggerName());
assertEquals(expected, actual);
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class YamlLayoutTest method prepareYAMLForStacktraceTests.
private String prepareYAMLForStacktraceTests(final boolean stacktraceAsString) {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
// @formatter:off
final AbstractJacksonLayout layout = YamlLayout.newBuilder().setIncludeStacktrace(true).setStacktraceAsString(stacktraceAsString).build();
// @formatter:on
return layout.toSerializable(expected);
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class XmlLayoutTest method testMutableLogEvent.
@Test
public void testMutableLogEvent() throws Exception {
final AbstractJacksonLayout layout = XmlLayout.newBuilder().setLocationInfo(false).setProperties(false).setIncludeStacktrace(false).setAdditionalFields(new KeyValuePair[] { new KeyValuePair("KEY1", "VALUE1"), new KeyValuePair("KEY2", "${java:runtime}") }).setCharset(StandardCharsets.UTF_8).setConfiguration(ctx.getConfiguration()).build();
Log4jLogEvent logEvent = LogEventFixtures.createLogEvent();
final MutableLogEvent mutableEvent = new MutableLogEvent();
mutableEvent.initFrom(logEvent);
final String strLogEvent = layout.toSerializable(logEvent);
final String strMutableEvent = layout.toSerializable(mutableEvent);
assertEquals(strMutableEvent, strLogEvent, strMutableEvent);
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class Log4j1XmlLayoutTest method testWithoutThrown.
@Test
public void testWithoutThrown() {
final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(false, true);
final Log4jLogEvent event = Log4jLogEvent.newBuilder().setLoggerName("a.B").setLevel(Level.INFO).setMessage(new SimpleMessage("Hello, World")).setTimeMillis(System.currentTimeMillis() + 17).build();
final String result = layout.toSerializable(event);
final String expected = "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" + "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" + "</log4j:event>\r\n\r\n";
assertEquals(expected, result);
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class ExtendedThrowablePatternConverterTest method testDeserializedLogEventWithThrowableProxyButNoThrowable.
@Test
public void testDeserializedLogEventWithThrowableProxyButNoThrowable() {
final ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null, null);
final Throwable originalThrowable = new Exception("something bad happened");
final ThrowableProxy throwableProxy = new ThrowableProxy(originalThrowable);
final Throwable deserializedThrowable = null;
final Log4jLogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"testLogger").setLoggerFqcn(//
this.getClass().getName()).setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("")).setThrown(//
deserializedThrowable).setThrownProxy(//
throwableProxy).setTimeMillis(0).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String result = sb.toString();
assertTrue(result.contains(originalThrowable.getMessage()), result);
assertTrue(result.contains(originalThrowable.getStackTrace()[0].getMethodName()), result);
}
Aggregations