Search in sources :

Example 26 with AbstractJacksonLayout

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")));
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) Test(org.junit.Test)

Example 27 with AbstractJacksonLayout

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());
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) Test(org.junit.Test)

Example 28 with AbstractJacksonLayout

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);
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) AbstractLogger(org.apache.logging.log4j.spi.AbstractLogger) Test(org.junit.Test)

Example 29 with AbstractJacksonLayout

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);
}
Also used : KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) MutableLogEvent(org.apache.logging.log4j.core.impl.MutableLogEvent) Test(org.junit.Test)

Example 30 with AbstractJacksonLayout

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);
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout)

Aggregations

AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)32 Test (org.junit.Test)26 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)7 Log4jJsonObjectMapper (org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper)5 Appender (org.apache.logging.log4j.core.Appender)4 Configuration (org.apache.logging.log4j.core.config.Configuration)4 MutableLogEvent (org.apache.logging.log4j.core.impl.MutableLogEvent)4 ListAppender (org.apache.logging.log4j.core.test.appender.ListAppender)4 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)4 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)4 JavaLookup (org.apache.logging.log4j.core.lookup.JavaLookup)3 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)2 Log4jYamlObjectMapper (org.apache.logging.log4j.jackson.yaml.Log4jYamlObjectMapper)2 Message (org.apache.logging.log4j.message.Message)2 RingBufferLogEvent (org.apache.logging.log4j.core.async.RingBufferLogEvent)1 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)1