use of org.apache.logging.log4j.core.layout.PatternLayout in project ignite by apache.
the class Log4J2Logger method createConsoleLogger.
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
public static Logger createConsoleLogger() {
LoggerContext ctx = (LoggerContext) LogManager.getContext(true);
Configuration cfg = ctx.getConfiguration();
PatternLayout.Builder builder = PatternLayout.newBuilder();
builder.withPattern("%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n").withCharset(Charset.defaultCharset()).withAlwaysWriteExceptions(false).withNoConsoleNoAnsi(false);
PatternLayout layout = builder.build();
ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder();
consoleAppenderBuilder.withName(CONSOLE_APPENDER).withLayout(layout);
ConsoleAppender consoleApp = consoleAppenderBuilder.build();
consoleApp.start();
AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, Level.TRACE, null);
AppenderRef[] refs = { ref };
LoggerConfig logCfg = LoggerConfig.createLogger(false, Level.INFO, LogManager.ROOT_LOGGER_NAME, "", refs, null, null, null);
logCfg.addAppender(consoleApp, null, null);
cfg.addAppender(consoleApp);
cfg.addLogger(LogManager.ROOT_LOGGER_NAME, logCfg);
ctx.updateLoggers(cfg);
return (Logger) LogManager.getContext().getLogger(LogManager.ROOT_LOGGER_NAME);
}
use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testConsoleSimpleLayout.
@Test
public void testConsoleSimpleLayout() throws Exception {
final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-SimpleLayout.properties");
assertEquals("%level - %m%n", layout.getConversionPattern());
}
use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.
the class LookupTest method testHostname.
@Test
public void testHostname() {
final ConsoleAppender app = context.getRequiredAppender("console", ConsoleAppender.class);
final Layout<?> layout = app.getLayout();
assertNotNull("No Layout", layout);
assertTrue("Layout is not a PatternLayout", layout instanceof PatternLayout);
final String pattern = ((PatternLayout) layout).getConversionPattern();
assertNotNull("No conversion pattern", pattern);
assertTrue("No filters", pattern.contains("org.junit,org.apache.maven,org.eclipse,sun.reflect,java.lang.reflect"));
}
use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.
the class ConsoleAppenderBuilderTest method testDefaultLayoutDefaultCharset.
/**
* Tests https://issues.apache.org/jira/browse/LOG4J2-1636
*
* Tested with Oracle 7 and 8 and IBM Java 8.
*/
@Test
public void testDefaultLayoutDefaultCharset() {
final ConsoleAppender appender = ConsoleAppender.newBuilder().withName("test").build();
final PatternLayout layout = (PatternLayout) appender.getLayout();
final String charsetName = System.getProperty("sun.stdout.encoding");
final String expectedName = charsetName != null ? charsetName : Charset.defaultCharset().name();
Assert.assertEquals(expectedName, layout.getCharset().name());
}
use of org.apache.logging.log4j.core.layout.PatternLayout in project logging-log4j2 by apache.
the class InMemoryAppenderTest method testHeaderRequested.
@Test
public void testHeaderRequested() {
final PatternLayout layout = PatternLayout.newBuilder().withHeader("HEADERHEADER").build();
final boolean writeHeader = true;
final InMemoryAppender app = new InMemoryAppender("test", layout, null, false, writeHeader);
final String expectedHeader = "HEADERHEADER";
assertMessage("Test", app, expectedHeader);
}
Aggregations