diff --git a/org.eclipse.m2e.logback/META-INF/MANIFEST.MF b/org.eclipse.m2e.logback/META-INF/MANIFEST.MF
index 0dc4aa025a..e97d75b2bd 100644
--- a/org.eclipse.m2e.logback/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.logback/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.m2e.logback;singleton:=true
-Bundle-Version: 2.1.100.qualifier
+Bundle-Version: 2.1.101.qualifier
Bundle-Name: M2E Logback Appender and Configuration
Bundle-Vendor: Eclipse.org - m2e
Bundle-RequiredExecutionEnvironment: JavaSE-17
diff --git a/org.eclipse.m2e.logback/defaultLogbackConfiguration/logback.xml b/org.eclipse.m2e.logback/defaultLogbackConfiguration/logback.xml
index abdf1c7373..9effde76cb 100644
--- a/org.eclipse.m2e.logback/defaultLogbackConfiguration/logback.xml
+++ b/org.eclipse.m2e.logback/defaultLogbackConfiguration/logback.xml
@@ -4,7 +4,7 @@
%date [%thread] %-5level %logger{35} - %msg%n
- OFF
+ ${org.eclipse.m2e.log.console.threshold:-OFF}
@@ -31,7 +31,7 @@
-
+
diff --git a/org.eclipse.m2e.logback/src/org/eclipse/m2e/logback/configuration/M2ELogbackConfigurator.java b/org.eclipse.m2e.logback/src/org/eclipse/m2e/logback/configuration/M2ELogbackConfigurator.java
index d2dd5b4e16..91ac2b864c 100644
--- a/org.eclipse.m2e.logback/src/org/eclipse/m2e/logback/configuration/M2ELogbackConfigurator.java
+++ b/org.eclipse.m2e.logback/src/org/eclipse/m2e/logback/configuration/M2ELogbackConfigurator.java
@@ -19,6 +19,8 @@
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.SortedMap;
import java.util.Timer;
@@ -27,14 +29,18 @@
import java.util.function.BooleanSupplier;
import org.osgi.framework.Bundle;
+import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.osgi.service.environment.EnvironmentInfo;
import ch.qos.logback.classic.BasicConfigurator;
+import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.spi.Configurator;
@@ -51,9 +57,12 @@ public class M2ELogbackConfigurator extends BasicConfigurator implements Configu
// This has to match the log directory in defaultLogbackConfiguration/logback.xml
private static final String PROPERTY_LOG_DIRECTORY = "org.eclipse.m2e.log.dir"; //$NON-NLS-1$
+ // This has to match the log directory in defaultLogbackConfiguration/logback.xml
+ private static final String PROPERTY_LOG_CONSOLE_THRESHOLD = "org.eclipse.m2e.log.console.threshold"; //$NON-NLS-1$
+
@Override
public void configure(LoggerContext lc) {
- // Bug 337167: Configuring Logback requires the state-location. If not yet initialized it will be initialized to the default value,
+ // Bug 337167: Configuring Logback requires the state-location. If not yet initialized it will be initialized to the default value,
// but this prevents the workspace-chooser dialog to show up in a stand-alone Eclipse-product. Therefore we have to wait until the resources plug-in has started.
// This happens if a Plug-in that uses SLF4J is started before the workspace has been selected.
if(!isStateLocationInitialized()) {
@@ -84,9 +93,14 @@ private synchronized void configureLogback(LoggerContext lc) {
if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) { //$NON-NLS-1$
System.setProperty(PROPERTY_LOG_DIRECTORY, stateDir.toAbsolutePath().toString());
}
+ if(System.getProperty(PROPERTY_LOG_CONSOLE_THRESHOLD, "").length() <= 0) { //$NON-NLS-1$
+ if(isConsoleLogEnable()) {
+ System.setProperty(PROPERTY_LOG_CONSOLE_THRESHOLD, Level.DEBUG.levelStr);
+ }
+ }
loadConfiguration(lc, configFile.toUri().toURL());
- //Delete old logs in legacy logback plug-in's state location. Can sum up to 1GB of disk-space.
+ //Delete old logs in legacy logback plug-in's state location. Can sum up to 1GB of disk-space.
// TODO: can be removed when some time has passed and it is unlikely old workspaces that need clean-up are used.
Path legacyLogbackState = stateDir.resolveSibling("org.eclipse.m2e.logback.configuration");
if(Files.isDirectory(legacyLogbackState)) {
@@ -100,7 +114,17 @@ private synchronized void configureLogback(LoggerContext lc) {
Files.delete(legacyLogbackState);
}
} catch(Exception e) {
- LOG.log(Status.warning("Exception while setting up logging:" + e.getMessage(), e)); //$NON-NLS-1$
+ LOG.log(Status.warning("Exception while setting up logging:" + e.getMessage(), e));
+ }
+ }
+
+ private boolean isConsoleLogEnable() {
+ ServiceTracker tracker = openServiceTracker(EnvironmentInfo.class);
+ try {
+ EnvironmentInfo environmentInfo = (EnvironmentInfo) tracker.getService();
+ return environmentInfo != null && "true".equals(environmentInfo.getProperty("eclipse.consoleLog")); //$NON-NLS-1$
+ } finally {
+ tracker.close();
}
}
@@ -113,9 +137,37 @@ private static void loadConfiguration(LoggerContext lc, URL configFile) throws J
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+ applyDebugLogLevels(lc);
+
logJavaProperties(LoggerFactory.getLogger(M2ELogbackConfigurator.class));
}
+ private static void applyDebugLogLevels(LoggerContext lc) {
+ ServiceTracker tracker = openServiceTracker(DebugOptions.class);
+ try {
+ DebugOptions debugOptions = (DebugOptions) tracker.getService();
+ if(debugOptions != null) {
+ Map options = debugOptions.getOptions();
+ for(Entry entry : options.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+ if(key.endsWith("/debugLog") && "true".equals(value)) {
+ lc.getLogger(key.replace("/debugLog", "")).setLevel(Level.DEBUG);
+ }
+ }
+ }
+ } finally {
+ tracker.close();
+ }
+ }
+
+ private static ServiceTracker openServiceTracker(Class serviceClass) {
+ Bundle bundle = Platform.getBundle("org.eclipse.m2e.core"); // fragments don't have a BundleContext
+ ServiceTracker tracker = new ServiceTracker<>(bundle.getBundleContext(), serviceClass, null);
+ tracker.open();
+ return tracker;
+ }
+
// --- utility methods ---
private static boolean isStateLocationInitialized() {