[Title] fix logger bug
authorho.namkoong <ho.namkoong@samsung.com>
Mon, 15 Apr 2013 09:22:50 +0000 (18:22 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Mon, 15 Apr 2013 09:24:08 +0000 (18:24 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: Ifa809bfe8579d555da122ff02110c500b4333e3e

org.tizen.common/src/org/tizen/common/ui/page/preference/TizenBasePreferencePage.java
org.tizen.common/src/org/tizen/common/util/log/EclipseAppender.java
org.tizen.common/src/org/tizen/common/util/log/Level.java
org.tizen.common/src/org/tizen/common/util/log/messages.properties

index 07ea80a..a9ed253 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.DirectoryFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
@@ -100,7 +99,7 @@ public class TizenBasePreferencePage extends FieldEditorPreferencePage implement
     public static final String OPTION_ID_PERFORM = "org.tizen.common.logger.perform";
     
     private static final int DEFAULT_LEVEL = 1;
-    private static final Level[] LEVELS = {Level.OFF, Level.FATAL, Level.ERROR, Level.WARNING, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL};
+    private static final Level[] LEVELS = {Level.OFF, Level.ERROR, Level.INFO, Level.DEBUG, Level.ALL};
     
     private Text loggerCP;
     private Text loggerLocText;
index 487190c..54f7da3 100644 (file)
@@ -34,6 +34,10 @@ import org.apache.log4j.Level;
 import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.spi.ThrowableInformation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.tizen.common.CommonPlugin;
+import org.tizen.common.ui.view.console.ConsoleManager;
 
 /**
  * appends log to the Eclipse error log view
@@ -78,39 +82,44 @@ public class EclipseAppender extends AppenderSkeleton{
      * @author Ho Namkoong {@literal <ho.namkoong@samsung.com>} (S-Core)
      */
     @Override
-    protected void append(LoggingEvent arg0) {
+    protected void append(LoggingEvent event) {
         try {
-            int level = arg0.getLevel().toInt();
-            ThrowableInformation tI = arg0.getThrowableInformation();
+            Level level = event.getLevel();
+            ThrowableInformation tI = event.getThrowableInformation();
             Throwable t = null;
             if(tI != null) {
                 t = tI.getThrowable();
             }
             
-            String message = getLayout().format(arg0);
+            String message = getLayout().format(event);
+            String caller = event.getLocationInformation().getClassName();
             
-            switch (level) {
-            case Level.ERROR_INT:
-                Logger.error(message, t);
-                break;
-            case Level.WARN_INT:
-                Logger.warning(message, t);
-                break;
-            case Level.DEBUG_INT:
-                Logger.debug(message, t);
-                break;
-            case Level.FATAL_INT:
-                Logger.error(message, t);
-                break;
-            case Level.INFO_INT:
-                Logger.info(message, t);
-                break;
-            default:
-                break;
+            if(level.isGreaterOrEqual(Level.OFF)) {
+                return;
+            }
+            if(level.isGreaterOrEqual(Level.ERROR)) {
+                log(new Status(Status.ERROR, caller, message.toString(), t));
+            }
+            else if(level.isGreaterOrEqual(Level.WARN)) {
+                log(new Status(Status.WARNING, caller, message.toString(), t));
+            }
+            else if(level.isGreaterOrEqual(Level.INFO)) {
+                log(new Status(Status.INFO, caller, message.toString(), t));
             }
         }
         catch(Throwable t) {
-            LogLog.error(MessageFormat.format("Exception occurred while logging message: {0}", arg0.getMessage()), t);
+            LogLog.error(MessageFormat.format("Exception occurred while logging message: {0}", event.getMessage()), t);
+        }
+    }
+    
+    
+    private static void log(IStatus status) {
+        CommonPlugin plugin = CommonPlugin.getDefault();
+        if (plugin != null) {
+            plugin.getLog().log(status);
+        } else {
+            ConsoleManager conManager = new ConsoleManager("Error Log", false);
+            conManager.println(status.getPlugin() + " : " + status.getMessage());
         }
     }
 }
index cfd09e6..5ac85b0 100644 (file)
@@ -58,21 +58,11 @@ public class Level extends org.apache.log4j.Level{
     public static final Level OFF = new Level(org.apache.log4j.Level.OFF, Messages.LOGGER_OFF_DES);
     
     /**
-     * Logging level fatal
-     */
-    public static final Level FATAL = new Level(org.apache.log4j.Level.FATAL, Messages.LOGGER_FATAL_DES);
-    
-    /**
      * Logging level error
      */
     public static final Level ERROR = new Level(org.apache.log4j.Level.ERROR, Messages.LOGGER_ERROR_DES);
     
     /**
-     * Logging level warning
-     */
-    public static final Level WARNING = new Level(org.apache.log4j.Level.WARN, Messages.LOGGER_WARNING_DES);
-    
-    /**
      * Logging level info
      */
     public static final Level INFO = new Level(org.apache.log4j.Level.INFO, Messages.LOGGER_INFO_DES);
@@ -83,11 +73,6 @@ public class Level extends org.apache.log4j.Level{
     public static final Level DEBUG = new Level(org.apache.log4j.Level.DEBUG, Messages.LOGGER_DEBUG_DES);
     
     /**
-     * Logging level trace
-     */
-    public static final Level TRACE = new Level(org.apache.log4j.Level.TRACE, Messages.LOGGER_TRACE_DES);
-    
-    /**
      * Logging level all
      */
     public static final Level ALL = new Level(org.apache.log4j.Level.ALL, Messages.LOGGER_ALL_DES);
index 4d452a7..3ec226c 100644 (file)
@@ -3,11 +3,8 @@ FileAppender_EXCEPTION_CREATING_LOGFILE=Exception occurred while creating log fi
 FileAppender_EXCEPTION_FLUSHING_BUFFER=Exception occurred while flushing buffer.
 FileAppender_EXCEPTION_WRITING_LOG=Exception occurred while writing log message.
 FileAppender_EXCEPTION_DIRECTORY_EXISTING=Log File {0} already exists as a directory.
-LOGGER_FATAL_DES=FATAL: very severe error events that will presumably lead the application to abort
-LOGGER_TRACE_DES=TRACE: finer-grained informational events than the DEBUG
 LOGGER_OFF_DES=OFF: the highest possible rank and is intended to turn off logging
 LOGGER_ERROR_DES=ERROR: error events that might still allow the application to continue running
-LOGGER_WARNING_DES=WARNING: events that are potentially harmful situations
 LOGGER_INFO_DES=INFO: informational messages that highlight the progress of the application at coarse-grained level
 LOGGER_DEBUG_DES=DEBUG: fine-grained informational events that are most useful to debug an application
 LOGGER_ALL_DES=ALL: the lowest possible rank and is intended to turn on all logging