use of ch.qos.logback.core.joran.spi.JoranException in project GeoGig by boundlessgeo.
the class Logging method tryConfigureLogging.
static void tryConfigureLogging(Platform platform) {
// instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get
// some logging events before having configured logging
final Optional<URL> geogigDirUrl = new ResolveGeogigDir(platform).call();
if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getProtocol())) {
// redirect java.util.logging to SLF4J anyways
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
return;
}
final File geogigDir;
try {
geogigDir = new File(geogigDirUrl.get().toURI());
} catch (URISyntaxException e) {
throw Throwables.propagate(e);
}
if (geogigDir.equals(geogigDirLoggingConfiguration)) {
return;
}
if (!geogigDir.exists() || !geogigDir.isDirectory()) {
return;
}
final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir);
if (loggingFile == null) {
return;
}
try {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
/*
* Set the geogigdir variable for the config file can resolve the default location
* ${geogigdir}/log/geogig.log
*/
loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath());
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
configurator.doConfigure(loggingFile);
// redirect java.util.logging to SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
geogigDirLoggingConfiguration = geogigDir;
} catch (JoranException e) {
LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e);
}
}
use of ch.qos.logback.core.joran.spi.JoranException in project gocd by gocd.
the class LogConfigurator method configureWith.
protected void configureWith(URL resource) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext((LoggerContext) loggerFactory);
((LoggerContext) loggerFactory).reset();
// the statusManager keeps a copy of all logback status messages even after reset, so we clear that
((LoggerContext) loggerFactory).getStatusManager().clear();
try {
configurator.doConfigure(resource);
} catch (JoranException ignore) {
}
StatusPrinter.printInCaseOfErrorsOrWarnings((Context) loggerFactory);
}
use of ch.qos.logback.core.joran.spi.JoranException in project sulky by huxi.
the class LoggingTestBase method resetLogging.
@SuppressWarnings({ "PMD.AvoidPrintStackTrace" })
public static void resetLogging(boolean verbose) {
if (verbose) {
System.out.println("### Resetting logging configuration.");
}
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (loggerFactory instanceof LoggerContext) {
LoggerContext loggerContext = (LoggerContext) loggerFactory;
// reset previous configuration initially loaded from logback.xml
if (verbose) {
System.out.println("\nAbout to reset logging system.");
}
loggerContext.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
URL configUrl;
configUrl = LoggingTestBase.class.getResource("/logback-test.xml");
if (configUrl == null) {
configUrl = LoggingTestBase.class.getResource("/logback.xml");
}
try {
configurator.doConfigure(configUrl);
if (verbose) {
System.out.println("\nPrinting status of logging system:");
StatusPrinter.print(loggerContext);
}
} catch (JoranException ex) {
System.err.println("!!! Error configuring logging framework with '" + configUrl + "'!");
// this is not a bug! - Avoid Print Stack Trace : Avoid printStackTrace(); use a logger call instead.
ex.printStackTrace();
StatusPrinter.print(loggerContext);
}
}
}
Aggregations