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());
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations