Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvladt2011-03-10 18:30:35 +0000
committervladt2011-03-10 18:31:34 +0000
commitb37f2a1a8337a0ce0cfe094acd397bdffe87a070 (patch)
treeb9f3822abe3e337169b7fc581020b077fa1e2687
parent88c1c7315bd943ed990fb503cfcd8de69eb0b214 (diff)
downloadm2e-core-b37f2a1a8337a0ce0cfe094acd397bdffe87a070.tar.gz
m2e-core-b37f2a1a8337a0ce0cfe094acd397bdffe87a070.tar.xz
m2e-core-b37f2a1a8337a0ce0cfe094acd397bdffe87a070.zip
339567: Log to console only if -consoleLog was passed as arg to eclipse
-rw-r--r--org.eclipse.m2e.logback.appender/src/main/java/org/eclipse/m2e/logback/appender/ConsoleAppenderFilter.java38
-rw-r--r--org.eclipse.m2e.logback.configuration/defaultLogbackConfiguration/logback.xml1
-rw-r--r--org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java28
3 files changed, 60 insertions, 7 deletions
diff --git a/org.eclipse.m2e.logback.appender/src/main/java/org/eclipse/m2e/logback/appender/ConsoleAppenderFilter.java b/org.eclipse.m2e.logback.appender/src/main/java/org/eclipse/m2e/logback/appender/ConsoleAppenderFilter.java
new file mode 100644
index 00000000..ad680b4a
--- /dev/null
+++ b/org.eclipse.m2e.logback.appender/src/main/java/org/eclipse/m2e/logback/appender/ConsoleAppenderFilter.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.logback.appender;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.spi.FilterReply;
+
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
+
+
+/**
+ * Filters out (disables) logging to console if -consoleLog was passed as arg to eclipse
+ */
+@SuppressWarnings("restriction")
+public class ConsoleAppenderFilter extends Filter<ILoggingEvent> {
+ private boolean consoleLogEnabled;
+
+ public ConsoleAppenderFilter() {
+ consoleLogEnabled = "true".equals(FrameworkProperties.getProperty(EclipseStarter.PROP_CONSOLE_LOG));
+ }
+
+ public FilterReply decide(ILoggingEvent loggingEvent) {
+ if(consoleLogEnabled) {
+ return FilterReply.NEUTRAL;
+ }
+ return FilterReply.DENY;
+ }
+}
diff --git a/org.eclipse.m2e.logback.configuration/defaultLogbackConfiguration/logback.xml b/org.eclipse.m2e.logback.configuration/defaultLogbackConfiguration/logback.xml
index d4f09c2c..d086c568 100644
--- a/org.eclipse.m2e.logback.configuration/defaultLogbackConfiguration/logback.xml
+++ b/org.eclipse.m2e.logback.configuration/defaultLogbackConfiguration/logback.xml
@@ -3,6 +3,7 @@
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date [%thread] %-5level %logger{35} - %msg%n</Pattern>
</layout>
+ <filter class="org.eclipse.m2e.logback.appender.ConsoleAppenderFilter"/>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
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 375e7c2d..cf3599d0 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
@@ -33,8 +33,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
+@SuppressWarnings("restriction")
public class LogPlugin extends Plugin {
private static final String PLUGIN_ID = "org.eclipse.m2e.logback.configuration"; //$NON-NLS-1$
@@ -66,13 +69,14 @@ public class LogPlugin extends Plugin {
// The standard logback config file property is set - don't force our configuration
systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "=" //$NON-NLS-1$
+ System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY));
+ return;
+ }
+
+ if(!Platform.getInstanceLocation().isSet()) {
+ systemOut("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized."); //$NON-NLS-1$ //$NON-NLS-2$
+ timer.schedule(timerTask, 0 /*delay*/, 50 /*period*/);
} else {
- if(!Platform.getInstanceLocation().isSet()) {
- systemOut("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized."); //$NON-NLS-1$ //$NON-NLS-2$
- timer.schedule(timerTask, 0 /*delay*/, 50 /*period*/);
- } else {
- configureLogback();
- }
+ configureLogback();
}
}
@@ -164,7 +168,17 @@ public class LogPlugin extends Plugin {
configurator.setContext(lc);
configurator.doConfigure(configFile);
- StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+ systemOut(EclipseStarter.PROP_CONSOLE_LOG + "=" + FrameworkProperties.getProperty(EclipseStarter.PROP_CONSOLE_LOG));
+ boolean consoleLog = "true".equals(FrameworkProperties.getProperty(EclipseStarter.PROP_CONSOLE_LOG));
+ if(consoleLog) {
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+// } else {
+// Logger logger = (Logger) LoggerFactory.getLogger("root");
+// Appender consoleAppender = logger.getAppender("STDOUT");
+// if(consoleAppender != null && consoleAppender.isStarted()) {
+// consoleAppender.stop();
+// }
+ }
LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class));
}

Back to the top