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
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);
+ }
+ }
}
}
--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* NamKoong Ho <ho.namkoong@samsung.com>
+*
+* 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);
+ }
+}
--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* NamKoong Ho <ho.namkoong@samsung.com>
+*
+* 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<String, Button> buttonMap = new HashMap<String, Button>();
+ 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();
+ }
+
+}