Commit a77459bc authored by Luca Cristoforetti's avatar Luca Cristoforetti

Merge branch '32-have-log-levels-settable-from-command-line-and-application-wide' into 'master'

Resolve "Have log levels settable from command line and application wide"

Closes #32

See merge request ESProjects/SDE!34
parents b34a2602 9c17d602
......@@ -9,6 +9,8 @@
*******************************************************************************/
package eu.fbk.tools.adapter.ui;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
......@@ -24,6 +26,9 @@ public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "eu.fbk.tools.adapter.ui";
// The system property that contains the log level to use
public static final String LOG4J_LOG_LEVEL = "Log4jLogLevel";
// The shared instance
private static Activator plugin;
......@@ -43,10 +48,18 @@ public class Activator extends AbstractUIPlugin {
super.start(context);
plugin = this;
final String level = getPreferenceStore().getString(PreferenceConstants.LOG_LEVEL);
// Read the level from the system property or from the preferences
String level = System.getProperty(LOG4J_LOG_LEVEL);
if (level == null) {
level = getPreferenceStore().getString(PreferenceConstants.LOG_LEVEL);
}
// Set the log level for the ancestor logger
org.apache.log4j.Logger logger4j = org.apache.log4j.Logger.getLogger(ToolConsoleFactory.LOGGER_NAME);
logger4j.setLevel(org.apache.log4j.Level.toLevel(level));
// Change the level also for the root logger, influencing other plugin loggers
LogManager.getRootLogger().setLevel(Level.toLevel(level));
final Boolean clean = getPreferenceStore().getBoolean(PreferenceConstants.TOOL_WORKSPACE_CLEANUP);
if( clean )
......
......@@ -11,6 +11,7 @@ package eu.fbk.tools.adapter.ui.preferences.debug;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.BooleanFieldEditor;
......@@ -99,6 +100,9 @@ public class DebugPreferencePage extends CommonPreferencePage
final String level = getPreferenceStore().getString(PreferenceConstants.LOG_LEVEL);
Logger.getLogger("eu.fbk.tools").setLevel(Level.toLevel(level));
// Change the level also to the root logger, influencing other plugin loggers
LogManager.getRootLogger().setLevel(Level.toLevel(level));
final String enableMonolithicCheck = getPreferenceStore().getBoolean(PreferenceConstants.DEVELOPMENT_MODE) ? "true" : "false";
System.setProperty(DEVELOPMENT_MODE_PROPERTY_NAME, enableMonolithicCheck);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment