Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvladt2011-02-16 12:12:11 -0500
committervladt2011-02-16 12:12:11 -0500
commit4287901caaf4b6b46815790bccb57ed76038b88d (patch)
tree119b91ede1205302939bb59b472c24e734092468 /org.eclipse.m2e.logback.configuration/src
parent1b7e60673525ff1e3ef3038e08ff6f96af4577b4 (diff)
downloadm2e-core-4287901caaf4b6b46815790bccb57ed76038b88d.tar.gz
m2e-core-4287901caaf4b6b46815790bccb57ed76038b88d.tar.xz
m2e-core-4287901caaf4b6b46815790bccb57ed76038b88d.zip
335872: Made slf4j/logback initialization more robust
Diffstat (limited to 'org.eclipse.m2e.logback.configuration/src')
-rw-r--r--org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
index af71c2e2..5de2236a 100644
--- a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
+++ b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
@@ -17,7 +17,9 @@ import java.io.InputStream;
import java.net.URL;
import org.osgi.framework.BundleContext;
+import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
+import org.slf4j.helpers.SubstituteLoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
@@ -46,10 +48,14 @@ public class LogPlugin extends Plugin {
LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class));
}
- private void systemOut(String message) {
+ private static void systemOut(String message) {
System.out.println(PLUGIN_ID + ": " + message);
}
+ private static void systemErr(String message) {
+ System.err.println(PLUGIN_ID + ": " + message);
+ }
+
private void configureLogger(BundleContext context) {
if(System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) != null) {
systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "="
@@ -101,7 +107,34 @@ public class LogPlugin extends Plugin {
}
public static void loadConfiguration(URL configFile) throws JoranException {
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
+ int i = 0;
+ while(loggerFactory instanceof SubstituteLoggerFactory && i < 100) {
+ // slf4j is initialization phase
+ if(loggerFactory != null) {
+ systemOut("SLF4J logger factory class: " + loggerFactory.getClass().getName());
+ }
+ try {
+ Thread.sleep(50);
+ } catch(InterruptedException e) {
+ e.printStackTrace();
+ }
+ i++ ;
+ loggerFactory = LoggerFactory.getILoggerFactory();
+ }
+ if(!(loggerFactory instanceof LoggerContext)) {
+ if(loggerFactory == null) {
+ // Is it possible?
+ systemErr("SLF4J logger factory is null");
+ return;
+ }
+ systemErr("SLF4J logger factory is not an instance of LoggerContext: "
+ + loggerFactory.getClass().getName());
+ return;
+ }
+
+ systemOut("Initializing logback");
+ LoggerContext lc = (LoggerContext) loggerFactory;
lc.reset();
JoranConfigurator configurator = new JoranConfigurator();

Back to the top