Search in sources :

Example 16 with PatternLayout

use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.

the class InMemoryAppenderTest method testHeaderSuppressed.

@Test
public void testHeaderSuppressed() {
    final PatternLayout layout = PatternLayout.newBuilder().withHeader("HEADERHEADER").build();
    final boolean writeHeader = false;
    final InMemoryAppender app = new InMemoryAppender("test", layout, null, false, writeHeader);
    final String expectedHeader = null;
    assertMessage("Test", app, expectedHeader);
}
Also used : InMemoryAppender(org.apache.logging.log4j.test.appender.InMemoryAppender) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) Test(org.junit.Test)

Example 17 with PatternLayout

use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.

the class TestConfigurator method testEnvironment.

@Test
public void testEnvironment() throws Exception {
    ctx = Configurator.initialize("-config", null);
    LogManager.getLogger("org.apache.test.TestConfigurator");
    final Configuration config = ctx.getConfiguration();
    assertNotNull("No configuration", config);
    assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
    final Map<String, Appender> map = config.getAppenders();
    assertNotNull("Appenders map should not be null.", map);
    assertThat(map, hasSize(greaterThan(0)));
    assertThat("No ListAppender named List2", map, hasKey("List2"));
    final Appender app = map.get("List2");
    final Layout<? extends Serializable> layout = app.getLayout();
    assertNotNull("Appender List2 does not have a Layout", layout);
    assertThat("Appender List2 is not configured with a PatternLayout", layout, instanceOf(PatternLayout.class));
    final String pattern = ((PatternLayout) layout).getConversionPattern();
    assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
    assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) BuiltConfiguration(org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) Test(org.junit.Test)

Aggregations

PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)17 Test (org.junit.Test)12 LoggerContext (org.apache.logging.log4j.core.LoggerContext)5 Configuration (org.apache.logging.log4j.core.config.Configuration)5 Appender (org.apache.logging.log4j.core.Appender)4 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)3 File (java.io.File)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)2 InMemoryAppender (org.apache.logging.log4j.test.appender.InMemoryAppender)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 Layout (org.apache.logging.log4j.core.Layout)1 Logger (org.apache.logging.log4j.core.Logger)1 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)1 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)1 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)1