use of ch.qos.logback.classic.joran.JoranConfigurator in project cdap by caskdata.
the class RollingLocationLogAppenderTest method testRollingLocationLogAppender.
@Test
public void testRollingLocationLogAppender() throws Exception {
// assume SLF4J is bound to logback in the current environment
AppenderContext appenderContext = new LocalAppenderContext(injector.getInstance(DatasetFramework.class), injector.getInstance(TransactionSystemClient.class), injector.getInstance(LocationFactory.class), new NoOpMetricsCollectionService());
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(appenderContext);
// Call context.reset() to clear any previous configuration, e.g. default
// configuration. For multi-step configuration, omit calling context.reset().
appenderContext.reset();
configurator.doConfigure(getClass().getResourceAsStream("/rolling-appender-logback-test.xml"));
StatusPrinter.printInCaseOfErrorsOrWarnings(appenderContext);
RollingLocationLogAppender rollingAppender = (RollingLocationLogAppender) appenderContext.getLogger(RollingLocationLogAppenderTest.class).getAppender("rollingAppender");
addTagsToMdc("testNamespace", "testApp");
Logger logger = appenderContext.getLogger(RollingLocationLogAppenderTest.class);
ingestLogs(logger, 5);
Map<LocationIdentifier, LocationOutputStream> activeFiles = rollingAppender.getLocationManager().getActiveLocations();
Assert.assertEquals(1, activeFiles.size());
verifyFileOutput(activeFiles, 5);
// different program should go to different directory
addTagsToMdc("testNamespace", "testApp1");
ingestLogs(logger, 5);
activeFiles = rollingAppender.getLocationManager().getActiveLocations();
Assert.assertEquals(2, activeFiles.size());
verifyFileOutput(activeFiles, 5);
// different program should go to different directory because namespace is different
addTagsToMdc("testNamespace1", "testApp1");
ingestLogs(logger, 5);
activeFiles = rollingAppender.getLocationManager().getActiveLocations();
Assert.assertEquals(3, activeFiles.size());
verifyFileOutput(activeFiles, 5);
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project cdap by caskdata.
the class RollingLocationLogAppenderTest method testFileClose.
@Test
public void testFileClose() throws Exception {
// assume SLF4J is bound to logback in the current environment
AppenderContext appenderContext = new LocalAppenderContext(injector.getInstance(DatasetFramework.class), injector.getInstance(TransactionSystemClient.class), injector.getInstance(LocationFactory.class), new NoOpMetricsCollectionService());
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(appenderContext);
// Call context.reset() to clear any previous configuration, e.g. default
// configuration. For multi-step configuration, omit calling context.reset().
appenderContext.reset();
configurator.doConfigure(getClass().getResourceAsStream("/rolling-appender-logback-test.xml"));
StatusPrinter.printInCaseOfErrorsOrWarnings(appenderContext);
RollingLocationLogAppender rollingAppender = (RollingLocationLogAppender) appenderContext.getLogger(RollingLocationLogAppenderTest.class).getAppender("rollingAppender");
addTagsToMdc("testNs", "testApp");
Logger logger = appenderContext.getLogger(RollingLocationLogAppenderTest.class);
ingestLogs(logger, 20);
// wait for 500 ms so that file is eligible for closing
Thread.sleep(500);
// flush to make sure file is closed
rollingAppender.flush();
Assert.assertEquals(0, rollingAppender.getLocationManager().getActiveLocations().size());
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project camel by apache.
the class ITestApplication method overrideLoggingConfig.
private static void overrideLoggingConfig() {
URL logbackFile = ITestApplication.class.getResource("/spring-logback.xml");
if (logbackFile != null) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
// Call context.reset() to clear any previous configuration, e.g. default
// configuration. For multi-step configuration, omit calling context.reset().
context.reset();
configurator.doConfigure(logbackFile);
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project stashbot by palantir.
the class PluginLoggerFactory method init.
private void init() {
// Assumes LSF4J is bound to logback
context = (LoggerContext) LoggerFactory.getILoggerFactory();
// store the home dir to use for relative paths
context.putProperty("stash.home", homeDir);
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
InputStream is;
is = this.getClass().getClassLoader().getResourceAsStream("logback-test.xml");
if (is != null) {
stashRootLogger.info("Using logback-test.xml for logger settings");
} else {
stashRootLogger.info("Using logback.xml for logger settings");
is = this.getClass().getClassLoader().getResourceAsStream("logback.xml");
}
try {
configurator.doConfigure(is);
} catch (JoranException e) {
System.err.println("Error configuring logging framework" + e);
}
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project sonarqube by SonarSource.
the class Logback method configure.
/**
* Note that this method closes the input stream
*/
private static void configure(InputStream input, Map<String, String> substitutionVariables) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(configureContext(lc, substitutionVariables));
configurator.doConfigure(input);
} catch (JoranException e) {
// StatusPrinter will handle this
} finally {
IOUtils.closeQuietly(input);
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
Aggregations