use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testFile.
private Layout<?> testFile(final String configResource) throws Exception {
final Configuration configuration = getConfiguration(configResource);
final FileAppender appender = configuration.getAppender("File");
assertNotNull(appender);
assertEquals("target/mylog.txt", appender.getFileName());
//
final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
assertNotNull(loggerConfig);
assertEquals(Level.DEBUG, loggerConfig.getLevel());
configuration.start();
configuration.stop();
return appender.getLayout();
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testSystemProperties2.
@Test
public void testSystemProperties2() throws Exception {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-2.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
assertEquals("${java.io.tmpdir}/hadoop.log", appender.getFileName());
appender.stop(10, TimeUnit.SECONDS);
Path path = new File(appender.getFileName()).toPath();
Files.deleteIfExists(path);
path = new File("${java.io.tmpdir}").toPath();
Files.deleteIfExists(path);
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testSystemProperties1.
@Test
public void testSystemProperties1() throws Exception {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
assertEquals(tempFileName, appender.getFileName());
}
use of org.apache.logging.log4j.core.config.Configuration 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);
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class JsonLayoutTest 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 boolean propertiesAsList = false;
// @formatter:off
final AbstractJacksonLayout layout = JsonLayout.newBuilder().setConfiguration(configuration).setLocationInfo(true).setProperties(true).setPropertiesAsList(propertiesAsList).setComplete(true).setCompact(false).setEventEol(false).setIncludeStacktrace(true).build();
// @formatter:on
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.checkAt("{", 1, 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);
}
}
Aggregations