use of ch.qos.logback.classic.joran.JoranConfigurator in project weave by continuuity.
the class ServiceMain method configureLogger.
private void configureLogger() {
// Check if SLF4J is bound to logback in the current environment
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (!(loggerFactory instanceof LoggerContext)) {
return;
}
LoggerContext context = (LoggerContext) loggerFactory;
context.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
try {
File weaveLogback = new File(Constants.Files.LOGBACK_TEMPLATE);
if (weaveLogback.exists()) {
configurator.doConfigure(weaveLogback);
}
new ContextInitializer(context).autoConfig();
} catch (JoranException e) {
throw Throwables.propagate(e);
}
doConfigure(configurator, getLogConfig(getLoggerLevel(context.getLogger(Logger.ROOT_LOGGER_NAME))));
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project sonarqube by SonarSource.
the class LogbackHelper method resetFromXml.
/**
* Generally used to reset logback in logging tests
*/
public void resetFromXml(String xmlResourcePath) throws JoranException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(LogbackHelper.class.getResource(xmlResourcePath));
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project ninja by ninjaframework.
the class LogbackConfigurator method initConfiguration.
public static void initConfiguration(NinjaProperties ninjaProperties) {
// If that is the case we do nothing and leave everything to LogBack
if (System.getProperty(LOGBACK_CONFIGURATION_FILE_PROPERTY) != null) {
return;
}
// If not we check if we got a logback configurationFile declared
// in our application.conf and load it...
String logbackConfigurationFile = ninjaProperties.get(LOGBACK_CONFIGURATION_FILE_PROPERTY);
if (logbackConfigurationFile == null) {
return;
}
URL logbackConfigurationFileAsURL = getUrlForStringFromClasspathAsFileOrUrl(logbackConfigurationFile);
if (logbackConfigurationFileAsURL == null) {
logger.error("Cannot configure logger from {} provided in application.conf", logbackConfigurationFile);
return;
}
// At that point we got a valid Url for configuring Logback. Let's do it :)
// assume SLF4J is bound to logback in the current environment
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(logbackConfigurationFileAsURL);
} catch (JoranException je) {
// StatusPrinter will handle this
}
logger.info("Successfully configured application logging from: {}", logbackConfigurationFileAsURL);
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project stash-codesearch-plugin 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);
}
stashRootLogger.info("Logger using stash.home of " + homeDir);
}
use of ch.qos.logback.classic.joran.JoranConfigurator in project spring-boot by spring-projects.
the class LogbackLoggingSystem method configureByResourceUrl.
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext, URL url) throws JoranException {
if (url.toString().endsWith("xml")) {
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
configurator.setContext(loggerContext);
configurator.doConfigure(url);
} else {
new ContextInitializer(loggerContext).configureByResource(url);
}
}
Aggregations