use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.
the class YamlLayoutTest method testIncludeNullDelimiterFalse.
@Test
public void testIncludeNullDelimiterFalse() throws Exception {
final AbstractJacksonLayout layout = YamlLayout.newBuilder().setIncludeNullDelimiter(false).build();
final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
assertThat(str, not(endsWith("\0")));
}
use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.
the class YamlLayoutTest method testDefaultCharset.
@Test
public void testDefaultCharset() {
final AbstractJacksonLayout layout = YamlLayout.createDefaultLayout();
assertEquals(StandardCharsets.UTF_8, layout.getCharset());
}
use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.
the class YamlLayoutTest method testEscapeLayout.
@Test
public void testEscapeLayout() throws Exception {
final Map<String, Appender> appenders = this.rootLogger.getAppenders();
for (final Appender appender : appenders.values()) {
this.rootLogger.removeAppender(appender);
}
final Configuration configuration = rootLogger.getContext().getConfiguration();
// set up appender
final AbstractJacksonLayout layout = YamlLayout.newBuilder().setLocationInfo(true).setProperties(true).setIncludeStacktrace(true).setConfiguration(configuration).build();
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
this.rootLogger.addAppender(appender);
this.rootLogger.setLevel(Level.DEBUG);
// output starting message
this.rootLogger.debug("Here is a quote ' and then a double quote \"");
appender.stop();
final List<String> list = appender.getMessages();
this.checkAt("---", 0, list);
this.checkContains("level: \"DEBUG\"", list);
this.checkContains("message: \"Here is a quote ' and then a double quote \\\"\"", list);
this.checkContains("loggerFqcn: \"" + AbstractLogger.class.getName() + "\"", list);
for (final Appender app : appenders.values()) {
this.rootLogger.addAppender(app);
}
}
use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.
the class YamlLayoutTest method testMutableLogEvent.
@Test
public void testMutableLogEvent() throws Exception {
final AbstractJacksonLayout layout = YamlLayout.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.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.
the class XmlLayoutTest method prepareXMLForStacktraceTests.
private String prepareXMLForStacktraceTests(final boolean stacktraceAsString) {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
// @formatter:off
final AbstractJacksonLayout layout = XmlLayout.newBuilder().setCompact(true).setIncludeStacktrace(true).setStacktraceAsString(stacktraceAsString).build();
// @formatter:off
return layout.toSerializable(expected);
}
Aggregations