use of org.knime.core.node.NodeLogger.LEVEL in project knime-core by knime.
the class KNIMECorePlugin method start.
/**
* This method is called upon plug-in activation.
*
* @param context The OSGI bundle context
* @throws Exception If this plugin could not be started
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
if (!Boolean.getBoolean("java.awt.headless") && (Display.getCurrent() != null)) {
getImageRegistry();
}
try {
// get the preference store
// with the preferences for nr threads and tempDir
IPreferenceStore pStore = KNIMECorePlugin.getDefault().getPreferenceStore();
initMaxThreadCountProperty();
initTmpDirProperty();
// set log file level to stored
String logLevelFile = pStore.getString(HeadlessPreferencesConstants.P_LOGLEVEL_LOG_FILE);
NodeLogger.setAppenderLevelRange(NodeLogger.LOGFILE_APPENDER, LEVEL.valueOf(logLevelFile), LEVEL.FATAL);
final boolean enableWorkflowRelativeLogging = pStore.getBoolean(HeadlessPreferencesConstants.P_LOG_FILE_LOCATION);
NodeLogger.logInWorkflowDir(enableWorkflowRelativeLogging);
final boolean enableGlobalInWfLogging = pStore.getBoolean(HeadlessPreferencesConstants.P_LOG_GLOBAL_IN_WF_DIR);
NodeLogger.logGlobalMsgsInWfDir(enableGlobalInWfLogging);
pStore.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (event.getProperty().equals(HeadlessPreferencesConstants.P_MAXIMUM_THREADS)) {
if (!(event.getNewValue() instanceof Integer)) {
// not set, they send an empty string
return;
}
int count;
try {
count = (Integer) event.getNewValue();
KNIMEConstants.GLOBAL_THREAD_POOL.setMaxThreads(count);
} catch (Exception e) {
LOGGER.error("Unable to get maximum thread count " + " from preference page.", e);
}
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_TEMP_DIR)) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String dirName = (String) event.getNewValue();
if (dirName.isEmpty()) {
return;
}
File f = new File(dirName);
LOGGER.debug("Setting temp dir to " + f.getAbsolutePath());
try {
KNIMEConstants.setKNIMETempDir(f);
} catch (Exception e) {
LOGGER.error("Setting temp dir failed: " + e.getMessage(), e);
}
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOGLEVEL_LOG_FILE)) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String newName = (String) event.getNewValue();
if (newName.isEmpty()) {
return;
}
LEVEL level = LEVEL.WARN;
try {
level = LEVEL.valueOf(newName);
} catch (IllegalArgumentException iae) {
LOGGER.error("Invalid log level " + newName + ", using WARN");
}
NodeLogger.setAppenderLevelRange(NodeLogger.LOGFILE_APPENDER, level, LEVEL.FATAL);
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOG_FILE_LOCATION)) {
if (!(event.getNewValue() instanceof Boolean)) {
// when preferences are imported and this value is not set, they send an empty string
return;
}
Boolean enable = (Boolean) event.getNewValue();
NodeLogger.logInWorkflowDir(enable);
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOG_GLOBAL_IN_WF_DIR)) {
if (!(event.getNewValue() instanceof Boolean)) {
// when preferences are imported and this value is not set, they send an empty string
return;
}
Boolean enable = (Boolean) event.getNewValue();
NodeLogger.logGlobalMsgsInWfDir(enable);
} else if (P_LOGLEVEL_CONSOLE.equals(event.getProperty())) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String newName = (String) event.getNewValue();
if (newName.isEmpty()) {
return;
}
setLogLevel(newName);
} else if (HeadlessPreferencesConstants.P_DATABASE_DRIVERS.equals(event.getProperty())) {
String dbDrivers = (String) event.getNewValue();
initDatabaseDriver(dbDrivers);
} else if (HeadlessPreferencesConstants.P_DATABASE_TIMEOUT.equals(event.getProperty())) {
DatabaseConnectionSettings.setDatabaseTimeout(Integer.parseInt(event.getNewValue().toString()));
}
}
});
// end property listener
String logLevelConsole = pStore.getString(P_LOGLEVEL_CONSOLE);
if (!Boolean.getBoolean("java.awt.headless") && PlatformUI.isWorkbenchRunning()) {
try {
ConsoleViewAppender.FORCED_APPENDER.write(KNIMEConstants.WELCOME_MESSAGE);
ConsoleViewAppender.INFO_APPENDER.write("Log file is located at: " + KNIMEConstants.getKNIMEHomeDir() + File.separator + NodeLogger.LOG_FILE + "\n");
} catch (IOException ioe) {
LOGGER.error("Could not print welcome message: ", ioe);
}
setLogLevel(logLevelConsole);
}
// encryption key supplier registered with the eclipse framework
// and serves as a master key provider
KnimeEncryption.setEncryptionKeySupplier(new EclipseEncryptionKeySupplier());
// load database driver files from core preference page
String dbDrivers = pStore.getString(HeadlessPreferencesConstants.P_DATABASE_DRIVERS);
initDatabaseDriver(dbDrivers);
DatabaseConnectionSettings.setDatabaseTimeout(pStore.getInt(HeadlessPreferencesConstants.P_DATABASE_TIMEOUT));
} catch (Throwable e) {
LOGGER.error("Error while starting workbench, some setting may not have been applied properly: " + e.getMessage(), e);
}
}
Aggregations