From: ho.namkoong Date: Wed, 13 Feb 2013 06:45:14 +0000 (+0900) Subject: [Title] Implement preference page which can select logger level X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6cd0160c7132b749f5edd04009a636ca84257e57;p=sdk%2Fide%2Fcommon-eplugin.git [Title] Implement preference page which can select logger level [Type] [Module] [Priority] [Jira#] [Redmine#] 7571 [Problem] [Cause] [Solution] [TestCase] Change-Id: Ia1b6ea575786cda418884220a41e1e6ac44a0659 --- diff --git a/org.tizen.common/OSGI-INF/l10n/bundle.properties b/org.tizen.common/OSGI-INF/l10n/bundle.properties index 1f4622f..331d833 100644 --- a/org.tizen.common/OSGI-INF/l10n/bundle.properties +++ b/org.tizen.common/OSGI-INF/l10n/bundle.properties @@ -23,4 +23,5 @@ activity.description.3 = PopupMenus activity.name.6 = PopupMenus extension-point.name = Prompter RDS.name=Rapid Development Support -crashreporter = Crash Reporter \ No newline at end of file +crashreporter = Crash Reporter +preferences.logger.name = Tizen Logger \ No newline at end of file diff --git a/org.tizen.common/plugin.xml b/org.tizen.common/plugin.xml index 2ee1120..44650d0 100644 --- a/org.tizen.common/plugin.xml +++ b/org.tizen.common/plugin.xml @@ -38,6 +38,12 @@ id="org.tizen.common.preferences.rds" name="%RDS.name"> + + diff --git a/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java index 93ff866..297f056 100644 --- a/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java +++ b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java @@ -33,9 +33,12 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.spi.Configurator; import org.apache.log4j.spi.LoggerRepository; +import org.tizen.common.util.log.preference.TizenLoggerPreferencePage; public class TizenLog4Configurator implements Configurator { + private static Logger ROOT_LOGGER; + @Override public void doConfigure(InputStream arg0, LoggerRepository arg1) { // TODO Auto-generated method stub @@ -49,6 +52,24 @@ public class TizenLog4Configurator implements Configurator { rootLogger.removeAllAppenders(); Appender tizenAppender = new TizenLog4jAppender(); rootLogger.addAppender(tizenAppender); + ROOT_LOGGER = rootLogger; + } + + public static void setLoggerLevel(String level) { + if(ROOT_LOGGER != null) { + if(TizenLoggerPreferencePage.LEVEL_ERROR.equals(level)) { + ROOT_LOGGER.setLevel(Level.ERROR); + } + else if(TizenLoggerPreferencePage.LEVEL_WARN.equals(level)) { + ROOT_LOGGER.setLevel(Level.WARN); + } + else if(TizenLoggerPreferencePage.LEVEL_INFO.equals(level)) { + ROOT_LOGGER.setLevel(Level.INFO); + } + else if(TizenLoggerPreferencePage.LEVEL_DEBUG.equals(level)) { + ROOT_LOGGER.setLevel(Level.DEBUG); + } + } } } diff --git a/org.tizen.common/src/org/tizen/common/util/log/preference/Messages.java b/org.tizen.common/src/org/tizen/common/util/log/preference/Messages.java new file mode 100644 index 0000000..194a778 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/preference/Messages.java @@ -0,0 +1,46 @@ +/* +* Common +* +* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* NamKoong Ho +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.util.log.preference; + +import org.eclipse.osgi.util.NLS; +import org.tizen.common.CommonPlugin; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = CommonPlugin.PLUGIN_ID + ".util.log.preference.messages";//$NON-NLS-1$ + + private Messages() { + // Do not instantiate + } + + public static String TizenLoggerPreferencePage_Description; + public static String TizenLoggerPreferencePage_LevelGroupTitle; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } +} diff --git a/org.tizen.common/src/org/tizen/common/util/log/preference/TizenLoggerPreferencePage.java b/org.tizen.common/src/org/tizen/common/util/log/preference/TizenLoggerPreferencePage.java new file mode 100644 index 0000000..424afda --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/preference/TizenLoggerPreferencePage.java @@ -0,0 +1,140 @@ +/* +* Common +* +* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* NamKoong Ho +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ + +package org.tizen.common.util.log.preference; + +import java.util.HashMap; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.tizen.common.CommonPlugin; +import org.tizen.common.util.log.TizenLog4Configurator; + +public class TizenLoggerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + private static final IPreferenceStore prefStore = CommonPlugin.getDefault().getPreferenceStore(); + private Button selectedButton; + public static final String OPTION_ID_LEVEL = "org.tizen.common.logger.level"; + + public static final String LEVEL_ERROR = "&Error"; + public static final String LEVEL_WARN = "&Warning"; + public static final String LEVEL_INFO = "&Info"; + public static final String LEVEL_DEBUG = "&Debug"; + + private HashMap buttonMap = new HashMap(); + private final String[] levels = {LEVEL_ERROR, LEVEL_WARN, LEVEL_INFO, LEVEL_DEBUG}; + + public TizenLoggerPreferencePage() { + setDescription(Messages.TizenLoggerPreferencePage_Description); + } + + @Override + public void init(IWorkbench workbench) { + // TODO Auto-generated method stub + } + + @Override + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.None); + composite.setLayout(new GridLayout(1, false)); + + Group levelGroup = new Group(composite, SWT.None); + levelGroup.setLayout(new GridLayout(levels.length, false)); + levelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + levelGroup.setText(Messages.TizenLoggerPreferencePage_LevelGroupTitle); + + for(String level: levels) { + final Button radioButton = new Button(levelGroup, SWT.RADIO); + radioButton.setText(level); + buttonMap.put(level, radioButton); + radioButton.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + selectedButton = radioButton; + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + } + + String selection = prefStore.getString(OPTION_ID_LEVEL); + Button selected = buttonMap.get(selection); + + selectedButton = (selected != null) ? selected : buttonMap.get(LEVEL_ERROR); + selectedButton.setSelection(true); + + return composite; + } + + public static String getLoggerLevel() { + String level = prefStore.getString(OPTION_ID_LEVEL); + + if(level != null) { + return level; + } + + return LEVEL_ERROR; + } + + @Override + protected void performDefaults() { + selectedButton.setSelection(false); + Button defaultButton = buttonMap.get(LEVEL_ERROR); + defaultButton.setSelection(true); + selectedButton = defaultButton; + TizenLog4Configurator.setLoggerLevel(LEVEL_ERROR); + super.performDefaults(); + } + + @Override + protected void performApply() { + if(selectedButton != null) { + String selection = selectedButton.getText(); + prefStore.putValue(OPTION_ID_LEVEL, selection); + TizenLog4Configurator.setLoggerLevel(selection); + } + } + + @Override + public boolean performOk() { + performApply(); + return super.performOk(); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/log/preference/messages.properties b/org.tizen.common/src/org/tizen/common/util/log/preference/messages.properties new file mode 100644 index 0000000..79ab7a8 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/preference/messages.properties @@ -0,0 +1,2 @@ +TizenLoggerPreferencePage_Description=Set the preferences about the logger +TizenLoggerPreferencePage_LevelGroupTitle=Logger Level