use of ch.qos.logback.core.joran.spi.JoranException 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.core.joran.spi.JoranException 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.core.joran.spi.JoranException 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.core.joran.spi.JoranException in project chassis by Kixeye.
the class LoggingConfiguration method reloadLogging.
/**
* Reloads logging.
*
* @param logbackConfig XML containing the logback configuration
*/
public void reloadLogging(String logbackConfig) {
LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(logContext);
logContext.reset();
configurator.doConfigure(new ByteArrayInputStream(logbackConfig.getBytes(Charsets.UTF_8)));
} catch (JoranException je) {
// StatusPrinter will handle this
} catch (Exception ex) {
// Just in case, so we see a stacktrace
ex.printStackTrace();
}
StatusPrinter.printInCaseOfErrorsOrWarnings(logContext);
applicationContext.publishEvent(new LoggingReloadedApplicationEvent(this));
}
use of ch.qos.logback.core.joran.spi.JoranException in project perun by CESNET.
the class PerunLogbackConfigurator method configure.
@Override
public void configure(LoggerContext loggerContext) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
String confDir = System.getProperty("perun.conf.custom", "/etc/perun/");
File confFile = Paths.get(confDir, "logback.xml").toFile();
if (confFile.exists()) {
System.out.println("Loading logback config file " + confFile);
try {
// loads logback file
configurator.doConfigure(confFile.toString());
} catch (JoranException e) {
e.printStackTrace();
}
} else {
System.out.println("Loading logback-default.xml file from classpath");
try (InputStream configStream = this.getClass().getResourceAsStream("/logback-default.xml")) {
// loads logback file
configurator.doConfigure(configStream);
configStream.close();
} catch (IOException | JoranException e) {
e.printStackTrace();
System.out.println("Falling back to logback basic configurator");
BasicConfigurator basicConfigurator = new BasicConfigurator();
basicConfigurator.setContext(loggerContext);
basicConfigurator.configure(loggerContext);
}
}
}
Aggregations