Search in sources :

Example 11 with PatternLayout

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

the class Log4j1ConfigurationFactoryTest method testConsolePatternLayout.

@Test
public void testConsolePatternLayout() throws Exception {
    final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-PatternLayout.properties");
    assertEquals("%d{ISO8601} [%t][%c] %-5p: %m%n", layout.getConversionPattern());
}
Also used : PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) Test(org.junit.Test)

Example 12 with PatternLayout

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

the class Log4j1ConfigurationFactoryTest method testConsoleEnhancedPatternLayout.

@Test
public void testConsoleEnhancedPatternLayout() throws Exception {
    final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-EnhancedPatternLayout.properties");
    assertEquals("%d{ISO8601} [%t][%c] %-5p %properties %ndc: %m%n", layout.getConversionPattern());
}
Also used : PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) Test(org.junit.Test)

Example 13 with PatternLayout

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

the class Log4j1ConfigurationFactoryTest method testConsoleTtccLayout.

@Test
public void testConsoleTtccLayout() throws Exception {
    final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-TTCCLayout.properties");
    assertEquals("%r [%t] %p %notEmpty{%ndc }- %m%n", layout.getConversionPattern());
}
Also used : PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) Test(org.junit.Test)

Example 14 with PatternLayout

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

the class LoggerTest method testLog.

@Test
@SuppressWarnings("deprecation")
public void testLog() {
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("%d %C %L %m").build();
    final ListAppender appender = new ListAppender("List", null, layout, false, false);
    appender.start();
    final Logger root = Logger.getRootLogger();
    try {
        root.getLogger().addAppender(appender);
        root.setLevel(Level.INFO);
        final MyLogger log = new MyLogger(root);
        log.logInfo("This is a test", null);
        root.log(Priority.INFO, "Test msg2", null);
        root.log(Priority.INFO, "Test msg3");
        final List<String> msgs = appender.getMessages();
        assertTrue("Incorrect number of messages", msgs.size() == 3);
        final String msg = msgs.get(0);
        assertTrue("Message contains incorrect class name: " + msg, msg.contains(LoggerTest.class.getName()));
        appender.stop();
    } finally {
        root.getLogger().removeAppender(appender);
    }
}
Also used : PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Test(org.junit.Test)

Example 15 with PatternLayout

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

the class OutputStreamAppenderTest method addAppender.

/**
     * Tests that you can add an output stream appender dynamically.
     */
private void addAppender(final OutputStream outputStream, final String outputStreamName) {
    final LoggerContext context = LoggerContext.getContext(false);
    final Configuration config = context.getConfiguration();
    final PatternLayout layout = PatternLayout.createDefaultLayout(config);
    final Appender appender = OutputStreamAppender.createAppender(layout, null, outputStream, outputStreamName, false, true);
    appender.start();
    config.addAppender(appender);
    ConfigurationTestUtils.updateLoggers(appender, config);
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Configuration(org.apache.logging.log4j.core.config.Configuration) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

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