velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r748567 - in /velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime: log/Log.java resource/ResourceManagerImpl.java
Date Fri, 27 Feb 2009 15:58:21 GMT
Author: nbubna
Date: Fri Feb 27 15:58:20 2009
New Revision: 748567

URL: http://svn.apache.org/viewvc?rev=748567&view=rev
Log:
take advantage of varargs and String.format for Log improvements

Modified:
    velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/log/Log.java
    velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java

Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/log/Log.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/log/Log.java?rev=748567&r1=748566&r2=748567&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/log/Log.java (original)
+++ velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/log/Log.java Fri
Feb 27 15:58:20 2009
@@ -76,14 +76,24 @@
         return this.chute;
     }
 
-    protected void log(int level, Object message)
+    protected void log(int level, Object message, Object... args)
     {
-        getLogChute().log(level, String.valueOf(message));
+        if (getLogChute().isLevelEnabled(level))
+        {
+            String msg = String.valueOf(message);
+            msg = String.format(msg, args);
+            getLogChute().log(level, msg);
+        }
     }
 
-    protected void log(int level, Object message, Throwable t)
+    protected void log(int level, Object message, Throwable t, Object... args)
     {
-        getLogChute().log(level, String.valueOf(message), t);
+        if (getLogChute().isLevelEnabled(level))
+        {
+            String msg = String.valueOf(message);
+            msg = String.format(msg, args);
+            getLogChute().log(level, msg, t);
+        }
     }
 
     /**
@@ -99,9 +109,9 @@
      * Log a trace message.
      * @param message
      */
-    public void trace(Object message)
+    public void trace(Object message, Object... args)
     {
-        log(LogChute.TRACE_ID, message);
+        log(LogChute.TRACE_ID, message, args);
     }
 
     /**
@@ -109,9 +119,9 @@
      * @param message
      * @param t
      */
-    public void trace(Object message, Throwable t)
+    public void trace(Object message, Throwable t, Object... args)
     {
-        log(LogChute.TRACE_ID, message, t);
+        log(LogChute.TRACE_ID, message, t, args);
     }
 
     /**
@@ -127,9 +137,9 @@
      * Log a debug message.
      * @param message
      */
-    public void debug(Object message)
+    public void debug(Object message, Object... args)
     {
-        log(LogChute.DEBUG_ID, message);
+        log(LogChute.DEBUG_ID, message, args);
     }
 
     /**
@@ -137,9 +147,9 @@
      * @param message
      * @param t
      */
-    public void debug(Object message, Throwable t)
+    public void debug(Object message, Throwable t, Object... args)
     {
-        log(LogChute.DEBUG_ID, message, t);
+        log(LogChute.DEBUG_ID, message, t, args);
     }
 
     /**
@@ -155,9 +165,9 @@
      * Log an info message.
      * @param message
      */
-    public void info(Object message)
+    public void info(Object message, Object... args)
     {
-        log(LogChute.INFO_ID, message);
+        log(LogChute.INFO_ID, message, args);
     }
 
     /**
@@ -165,9 +175,9 @@
      * @param message
      * @param t
      */
-    public void info(Object message, Throwable t)
+    public void info(Object message, Throwable t, Object... args)
     {
-        log(LogChute.INFO_ID, message, t);
+        log(LogChute.INFO_ID, message, t, args);
     }
 
     /**
@@ -183,9 +193,9 @@
      * Log a warning message.
      * @param message
      */
-    public void warn(Object message)
+    public void warn(Object message, Object... args)
     {
-        log(LogChute.WARN_ID, message);
+        log(LogChute.WARN_ID, message, args);
     }
 
     /**
@@ -193,9 +203,9 @@
      * @param message
      * @param t
      */
-    public void warn(Object message, Throwable t)
+    public void warn(Object message, Throwable t, Object... args)
     {
-        log(LogChute.WARN_ID, message, t);
+        log(LogChute.WARN_ID, message, t, args);
     }
 
     /**
@@ -211,9 +221,9 @@
      * Log an error message.
      * @param message
      */
-    public void error(Object message)
+    public void error(Object message, Object... args)
     {
-        log(LogChute.ERROR_ID, message);
+        log(LogChute.ERROR_ID, message, args);
     }
 
     /**
@@ -221,11 +231,11 @@
      * @param message
      * @param t
      */
-    public void error(Object message, Throwable t)
+    public void error(Object message, Throwable t, Object... args)
     {
-        log(LogChute.ERROR_ID, message, t);
+        log(LogChute.ERROR_ID, message, t, args);
     }
-    
+
     /**
      * Creates a string that formats the template filename with line number
      * and column of the given Directive. We use this routine to provide a cosistent format
for displaying 

Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?rev=748567&r1=748566&r2=748567&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
(original)
+++ velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
Fri Feb 27 15:58:20 2009
@@ -106,7 +106,7 @@
         this.rsvc = rsvc;
         log = rsvc.getLog();
 
-        log.trace("Default ResourceManager initializing. (" + this.getClass() + ")");
+        log.trace("ResourceManager initializing: %s", this.getClass());
 
         assembleResourceLoaderInitializers();
 
@@ -239,8 +239,8 @@
             if (loaderConfiguration == null)
             {
                 log.debug("ResourceManager : No configuration information found "+
-                          "for resource loader named '" + loaderName +
-                          "' (id is "+loaderID+"). Skipping it...");
+                          "for resource loader named '%s' (id is %s). Skipping it...",
+                          loaderName, loaderID);
                 continue;
             }
 
@@ -447,9 +447,8 @@
 
                     if (logWhenFound && log.isDebugEnabled())
                     {
-                        log.debug("ResourceManager : found " + resourceName +
-                                  " with loader " +
-                                  resourceLoader.getClassName());
+                        log.debug("ResourceManager: found %s with loader ",
+                                  resourceName, resourceLoader.getClassName());
                     }
 
                     howOldItWas = resourceLoader.getLastModified(resource);
@@ -536,11 +535,8 @@
 
             if (!org.apache.commons.lang.StringUtils.equals(resource.getEncoding(), encoding))
             {
-                log.warn("Declared encoding for template '" +
-                             resource.getName() +
-                             "' is different on reload. Old = '" +
-                             resource.getEncoding() + "' New = '" + encoding);
-
+                log.warn("Declared encoding for template '%s' is different on reload. Old
= '%s' New = '%s'",
+                         resource.getName(), resource.getEncoding(), encoding);
                 resource.setEncoding(encoding);
             }
 



Mime
View raw message