You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/02/01 13:29:40 UTC

svn commit: r617487 - in /poi/trunk/src: documentation/content/xdocs/changes.xml documentation/content/xdocs/status.xml java/org/apache/poi/util/CommonsLogger.java java/org/apache/poi/util/POILogger.java java/org/apache/poi/util/SystemOutLogger.java

Author: nick
Date: Fri Feb  1 04:29:38 2008
New Revision: 617487

URL: http://svn.apache.org/viewvc?rev=617487&view=rev
Log:
Improvements to how SystemOutLogger and CommonsLogger log messages with exceptions, and avoid an infinite loop with certain log messages with exceptions - triggered by bug #44326

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/util/CommonsLogger.java
    poi/trunk/src/java/org/apache/poi/util/POILogger.java
    poi/trunk/src/java/org/apache/poi/util/SystemOutLogger.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=617487&r1=617486&r2=617487&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Fri Feb  1 04:29:38 2008
@@ -36,6 +36,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">44326 - Improvements to how SystemOutLogger and CommonsLogger log messages with exceptions, and avoid an infinite loop with certain log messages with exceptions</action>
            <action dev="POI-DEVELOPERS" type="add">Support for a completed Record based "pull" stream, via org.apache.poi.hssf.eventusermodel.HSSFRecordStream, to complement the existing "push" Event User Model listener stuff</action>
         </release>
         <release version="3.0.2-FINAL" date="2008-02-04">

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=617487&r1=617486&r2=617487&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Feb  1 04:29:38 2008
@@ -33,6 +33,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">44326 - Improvements to how SystemOutLogger and CommonsLogger log messages with exceptions, and avoid an infinite loop with certain log messages with exceptions</action>
            <action dev="POI-DEVELOPERS" type="add">Support for a completed Record based "pull" stream, via org.apache.poi.hssf.eventusermodel.HSSFRecordStream, to complement the existing "push" Event User Model listener stuff</action>
         </release>
         <release version="3.0.2-FINAL" date="2008-02-04">

Modified: poi/trunk/src/java/org/apache/poi/util/CommonsLogger.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/CommonsLogger.java?rev=617487&r1=617486&r2=617487&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/CommonsLogger.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/CommonsLogger.java Fri Feb  1 04:29:38 2008
@@ -22,8 +22,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.util.*;
-
 /**
  * A logger class that strives to make it as easy as possible for
  * developers to write log calls, while simultaneously making those
@@ -53,7 +51,6 @@
      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
      * @param obj1 The object to log.
      */
-
     public void log(final int level, final Object obj1)
     {
         if(level==FATAL)
@@ -96,6 +93,78 @@
           if(log.isTraceEnabled())
           {
             log.trace(obj1);
+          }
+        }
+    }
+    
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.  This is converted to a string.
+     * @param exception An exception to be logged
+     */
+    public void log(final int level, final Object obj1,
+                    final Throwable exception) 
+    {
+        if(level==FATAL)
+        {
+          if(log.isFatalEnabled())
+          {
+            if(obj1 != null)
+               log.fatal(obj1, exception);
+            else
+               log.fatal(exception);
+          }
+        }
+        else if(level==ERROR)
+        {
+          if(log.isErrorEnabled())
+          {
+            if(obj1 != null)
+               log.error(obj1, exception);
+            else
+               log.error(exception);
+          }
+        }
+        else if(level==WARN)
+        {
+          if(log.isWarnEnabled())
+          {
+            if(obj1 != null)
+               log.warn(obj1, exception);
+            else
+               log.warn(exception);
+          }
+        }
+        else if(level==INFO)
+        {
+          if(log.isInfoEnabled())
+          {
+        	if(obj1 != null)
+               log.info(obj1, exception);
+        	else
+        	   log.info(exception);
+          }
+        }
+        else if(level==DEBUG)
+        {
+          if(log.isDebugEnabled())
+          {
+        	if(obj1 != null)
+               log.debug(obj1, exception);
+        	else
+        	   log.debug(exception);
+          }
+        }
+        else
+        {
+          if(log.isTraceEnabled())
+          {
+        	if(obj1 != null)
+               log.trace(obj1, exception);
+        	else
+        	   log.trace(exception);
           }
         }
 

Modified: poi/trunk/src/java/org/apache/poi/util/POILogger.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/POILogger.java?rev=617487&r1=617486&r2=617487&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/POILogger.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/POILogger.java Fri Feb  1 04:29:38 2008
@@ -51,7 +51,24 @@
     
     abstract public void initialize(final String cat);
     
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.  This is converted to a string.
+     */
     abstract public void log(final int level, final Object obj1);
+    
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.  This is converted to a string.
+     * @param exception An exception to be logged
+     */
+    abstract public void log(final int level, final Object obj1,
+                    final Throwable exception);
+
 
     /**
      * Check if a logger is enabled to log at the specified level
@@ -237,17 +254,15 @@
     }
 
     /**
-     * Log a message
+     * Log an exception, without a message
      *
      * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
-     * @param obj1 The object to log.  This is converted to a string.
      * @param exception An exception to be logged
      */
 
-    public void log(final int level, final Object obj1,
-                    final Throwable exception)
+    public void log(final int level, final Throwable exception)
     {
-        log(level , obj1, exception);
+        log(level, null, exception);
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/util/SystemOutLogger.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/SystemOutLogger.java?rev=617487&r1=617486&r2=617487&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/SystemOutLogger.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/SystemOutLogger.java Fri Feb  1 04:29:38 2008
@@ -49,8 +49,24 @@
 
     public void log(final int level, final Object obj1)
     {
-        if (check(level))
+    	log(level, obj1, null);
+    }
+    
+    /**
+     * Log a message
+     *
+     * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
+     * @param obj1 The object to log.  This is converted to a string.
+     * @param exception An exception to be logged
+     */
+    public void log(final int level, final Object obj1,
+                    final Throwable exception) {
+        if (check(level)) {
             System.out.println("["+cat+"] "+obj1);
+            if(exception != null) {
+            	exception.printStackTrace(System.out);
+            }
+        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org