You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2008/11/30 18:43:45 UTC

svn commit: r721863 - in /incubator/jspwiki/trunk: ./ src/com/ecyrd/jspwiki/ src/com/ecyrd/jspwiki/log/ src/com/ecyrd/jspwiki/plugin/

Author: jalkanen
Date: Sun Nov 30 09:43:44 2008
New Revision: 721863

URL: http://svn.apache.org/viewvc?rev=721863&view=rev
Log:
Implemented a varargs interface for logging package.

Added:
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/package.html
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/Logger.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerImpl.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=721863&r1=721862&r2=721863&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Nov 30 09:43:44 2008
@@ -1,3 +1,11 @@
+2008-11-06  Janne Jalkanen <ja...@apache.org>
+
+        * 3.0.0-svn-17
+        
+        * Logging package now implements an varargs interface for
+        faster and more flexible logging.  Please see Logger javadocs
+        for further information.
+        
 2008-11-30 Harry Metske <me...@apache.org>
 
         * 3.0.0-svn-16

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=721863&r1=721862&r2=721863&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sun Nov 30 09:43:44 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "16";
+    public static final String     BUILD         = "17";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/Logger.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/Logger.java?rev=721863&r1=721862&r2=721863&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/Logger.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/Logger.java Sun Nov 30 09:43:44 2008
@@ -20,30 +20,103 @@
  */
 package com.ecyrd.jspwiki.log;
 
+import java.util.Formatter;
+
 /**
- * This is just a plain wrapper around the slf4j logging interface.
+ *  <p>This is just a plain wrapper around the slf4j logging interface with additional
+ *  varargs interfaces.  The varargs interfaces are useful because they are faster
+ *  to construct than the usual string concatenation, so you won't lose as much time
+ *  if you're not logging.  In addition, they allow for easy locale-specific numbers
+ *  and dates.</p>
+ *  <p>For example, these two logging statements are equivalent, but the latter does
+ *  not construct the string <i>every</i> time the log sentence is created, and
+ *  also is in general easier to read.</p>
+ *  <pre>
+ *     log.debug("Found "+list.size()+" elements of type '"+elementType+"'");
+ *     log.debug("Found %d elements of type '%s'", list.size, elementType );
+ *  </pre>
  * 
- * @author Harry Metske
- * @since 3.0
+ *  @author Harry Metske
+ *  @since 3.0
+ *  @see java.util.Formatter
  */
 public interface Logger
 {
+    /**
+     *  Log an error.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param params An array of parameters.
+     */
+    void error( String string, Object... params );
 
-    void error( String string );
-
-    void warn( String string );
+    /**
+     *  Log a warning.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param params An array of parameters.
+     */
+    void warn( String string, Object... params );
 
-    void info( String string );
+    /**
+     *  Log an informative message.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param params An array of parameters.
+     */
+    void info( String string, Object... params );
 
-    void debug( String string );
+    /**
+     *  Log a debug message.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param params An array of parameters.
+     */
+    void debug( String string, Object... params );
 
-    void error( String string, Throwable t );
+    /**
+     *  Log an error with an exception.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param t The exception to log. 
+     *  @param params An array of parameters.
+     */
+    void error( String string, Throwable t, Object... params );
 
-    void warn( String string, Throwable t );
+    /**
+     *  Log a warning with an exception.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param t The exception to log. 
+     *  @param params An array of parameters.
+     */
+    void warn( String string, Throwable t, Object... params );
 
-    void info( String string, Throwable t );
+    /**
+     *  Log an informative message with an exception.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param t The exception to log. 
+     *  @param params An array of parameters.
+     */
+    void info( String string, Throwable t, Object... params );
 
-    void debug( String string, Throwable t );
+    /**
+     *  Log a debug message with an exception.
+     *  
+     *  @param string The string to log.  May contain {@link Formatter} -specific
+     *  formatting codes.
+     *  @param t The exception to log. 
+     *  @param params An array of parameters.
+     */
+    void debug( String string, Throwable t, Object... params );
 
     /**
      *  Checks if ERROR messages are enabled for this Logger.

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerImpl.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerImpl.java?rev=721863&r1=721862&r2=721863&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerImpl.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerImpl.java Sun Nov 30 09:43:44 2008
@@ -20,6 +20,8 @@
  */
 package com.ecyrd.jspwiki.log;
 
+import java.util.Formatter;
+
 import org.slf4j.Logger;
 
 /**
@@ -31,7 +33,7 @@
 public class LoggerImpl implements com.ecyrd.jspwiki.log.Logger
 {
     Logger m_slf4jLogger = null;
-
+    
     /**
      * @param loggerName The name of the SFL4J Logger to find
      */
@@ -42,51 +44,99 @@
 
     /** {@inheritDoc} */
     
-    public void error( String string )
+    public void error( String string, Object... params )
     {
-        m_slf4jLogger.error( string );
+        if( isErrorEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.error( string );
+        }
     }
 
     /** {@inheritDoc} */
-    public void warn( String string )
+    public void warn( String string, Object... params )
     {
-        m_slf4jLogger.warn( string );
+        if( isWarnEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.warn( string );
+        }
     }
 
     /** {@inheritDoc} */
-    public void info( String string )
+    public void info( String string, Object... params )
     {
-        m_slf4jLogger.info( string );
+        if( isInfoEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.info( string );
+        }
     }
 
     /** {@inheritDoc} */
-    public void debug( String arg0 )
+    public void debug( String string, Object... params )
     {
-        m_slf4jLogger.debug( arg0 );
+        if( isDebugEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.debug( string );
+        }
     }
 
     /** {@inheritDoc} */
-    public void error( String string, Throwable t )
+    public void error( String string, Throwable t, Object... params )
     {
-        m_slf4jLogger.error( string, t );
+        if( isErrorEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.error( string, t );
+        }
     }
 
     /** {@inheritDoc} */
-    public void warn( String string, Throwable t )
+    public void warn( String string, Throwable t, Object... params )
     {
-        m_slf4jLogger.warn( string, t );
+        if( isWarnEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.warn( string, t );
+        }
     }
 
     /** {@inheritDoc} */
-    public void info( String string, Throwable t )
+    public void info( String string, Throwable t, Object... params )
     {
-        m_slf4jLogger.info( string, t );
+        if( isInfoEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+
+            m_slf4jLogger.info( string, t );
+        }
     }
 
     /** {@inheritDoc} */
-    public void debug( String string, Throwable t )
+    public void debug( String string, Throwable t, Object... params )
     {
-        m_slf4jLogger.debug( string, t );
+        if( isDebugEnabled() )
+        {
+            if( params.length > 0 )
+                string = String.format( string, params );
+        
+            m_slf4jLogger.debug( string, t );
+        }
     }
 
     /** {@inheritDoc} */

Added: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/package.html
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/package.html?rev=721863&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/package.html (added)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/package.html Sun Nov 30 09:43:44 2008
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html> <head>
+<title>com.ecyrd.jspwiki.log</title>
+</head>
+
+<body>
+
+Provides a generic logging interface to the JSPWiki.
+
+<h2>Package Specification</h2>
+
+<p>This package provides a simple logging interface for JSPWiki.  All logging is done
+through the classes in this package, so that we don't have to deal with the generic
+nastiness which is Java logging...</p>
+
+<h2>Related Documentation</h2>
+
+<hr>
+<!-- hhmts start -->Last modified: Sun Nov 14 14:12:36 EET 2004 <!-- hhmts end -->
+</body> </html>

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java?rev=721863&r1=721862&r2=721863&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java Sun Nov 30 09:43:44 2008
@@ -667,7 +667,7 @@
         name = pluginClass.getName();
         if(name != null)
         {
-            log.debug("Registering plugin [name]: " + name);
+            log.debug("Registering plugin [name]: %s", name);
             m_pluginClassMap.put(name, pluginClass);
         }
 
@@ -677,7 +677,7 @@
         {
             for( String a : aliases )
             {
-                log.debug("Registering plugin [shortName]: " + a);
+                log.debug("Registering plugin [shortName]: %s", a);
                 m_pluginClassMap.put(a, pluginClass);
             }
         }
@@ -686,7 +686,7 @@
         name = pluginClass.getClassName();
         if(name != null)
         {
-            log.debug("Registering plugin [className]: " + name);
+            log.debug("Registering plugin [className]: %s", name);
             m_pluginClassMap.put(name, pluginClass);
         }
 
@@ -708,6 +708,8 @@
         
         Set<Class<? extends WikiPlugin>> resultSet = resolver.getClasses();
         
+        log.debug( "Found %d plugins", resultSet.size() );
+        
         for( Class<? extends WikiPlugin> clazz : resultSet )
         {
             if( !clazz.isInterface() & !Modifier.isAbstract( clazz.getModifiers() ) )
@@ -906,7 +908,7 @@
                 }
                 catch( Exception e )
                 {
-                    log.info( "Cannot initialize plugin "+m_clazz.getCanonicalName(), e );
+                    log.info( "Cannot initialize plugin '%s'", e, m_clazz.getCanonicalName() );
                 }
             }
         }