Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java4
-rw-r--r--org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java37
2 files changed, 37 insertions, 4 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
index a68c80cf..2e139e57 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
@@ -15,7 +15,6 @@ import java.io.File;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.slf4j.Logger;
@@ -142,7 +141,8 @@ public class MavenPlugin extends Plugin {
if(m2eLogbackBundle.getState() != Bundle.ACTIVE) {
try {
m2eLogbackBundle.start(Bundle.START_TRANSIENT);
- } catch(BundleException e) {
+ } catch(Exception e) {
+ // Since the logging bundle was not initialized, we can't use slf4j to log this error
e.printStackTrace();
}
}
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