velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1769701 - in /velocity/tools/trunk: velocity-tools-generic/src/main/java/org/apache/velocity/tools/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/gener...
Date Mon, 14 Nov 2016 22:40:07 GMT
Author: cbrisson
Date: Mon Nov 14 22:40:07 2016
New Revision: 1769701

URL: http://svn.apache.org/viewvc?rev=1769701&view=rev
Log:
[tools] review logging configuration:

 - ToolManager logger should be re-initialized once the VelocityEngine has been initialized
 - Tools loggers initialization has been factorized in SafeConfig
 - new configuration keys:
   x loggerName, to let the user choose an explicit logger name for a tool/a toolbox/the whole
config
   x useClassLogger, to have the logger(s) use class name(s) for a tool/a toolbox/the whole
config



Modified:
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/MarkupTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SortTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserToolDeprecatedMethods.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolContext.java
Mon Nov 14 22:40:07 2016
@@ -45,6 +45,7 @@ public class ToolContext implements Cont
     public static final String ENGINE_KEY = "velocityEngine";
     public static final String LOCALE_KEY = "locale";
     public static final String LOG_KEY = "log";
+    public static final String TOOLKEY_KEY = "key";
     public static final String CATCH_EXCEPTIONS_KEY = "catchExceptions";
 
     private List<Toolbox> toolboxes = new ArrayList<Toolbox>();

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolInfo.java
Mon Nov 14 22:40:07 2016
@@ -24,7 +24,6 @@ import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.velocity.tools.ClassUtils;
 import org.apache.velocity.tools.config.SkipSetters;
 
 /**

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolManager.java
Mon Nov 14 22:40:07 2016
@@ -174,20 +174,25 @@ public class ToolManager
             {
                 if (log == null)
                 {
-                    if (velocity == null)
-                    {
-                        log = LoggerFactory.getLogger(ToolManager.class);
-                    }
-                    else
-                    {
-                        log = ConfigurationUtils.getLog(velocity, "tools");
-                    }
+                    initLog();
                 }
             }
         }
         return log;
     }
 
+    protected void initLog()
+    {
+        if (velocity == null)
+        {
+            log = LoggerFactory.getLogger(ToolManager.class);
+        }
+        else
+        {
+            log = ConfigurationUtils.getLog(velocity, "tools");
+        }
+    }
+
     public ToolContext createContext()
     {
         return createContext(null);

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
Mon Nov 14 22:40:07 2016
@@ -19,7 +19,9 @@ package org.apache.velocity.tools.config
  * under the License.
  */
 
-import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.velocity.tools.ToolContext;
 import org.apache.velocity.tools.ToolInfo;
 import org.apache.velocity.tools.ClassUtils;
 
@@ -56,7 +58,7 @@ public class ToolConfiguration extends C
         // ensure any non-default key is also set as a property
         if (key != null && !key.equals(getDefaultKey()))
         {
-            setProperty("key", key);
+            setProperty(ToolContext.TOOLKEY_KEY, key);
         }
     }
 
@@ -265,7 +267,10 @@ public class ToolConfiguration extends C
         }
         // it's ok to use this here, because we know it's the
         // first time properties have been added to this ToolInfo
-        info.addProperties(getPropertyMap());
+        Map<String,Object> properties = getPropertyMap();
+        // make sure key is present in properties, even for default properties
+        properties.put(ToolContext.TOOLKEY_KEY, getKey());
+        info.addProperties(properties);
         return info;
     }
 

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ClassTool.java
Mon Nov 14 22:40:07 2016
@@ -32,9 +32,6 @@ import java.util.List;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.tools.ClassUtils;
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
@@ -77,8 +74,6 @@ public class ClassTool extends SafeConfi
     public static final String INSPECT_KEY = "inspect";
     public static final String SHOW_DEPRECATED_KEY = "showDeprecated";
 
-    protected static Logger log = LoggerFactory.getLogger(ClassTool.class);
-    
     protected Class type;
     protected List<MethodSub> methods;
     protected List<ConstructorSub> constructors;

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
Mon Nov 14 22:40:07 2016
@@ -277,12 +277,12 @@ public class EscapeTool extends SafeConf
     /**
      * Escapes the characters in a <code>String</code> using JavaScript String
rules.
      * <br />
-     * Delegates the process to {@link StringEscapeUtils#escapeJavaScript(String)}.
+     * Delegates the process to {@link StringEscapeUtils#escapeEcmaScript(String)}.
      *
      * @param string the string to escape values, may be null
      * @return String with escaped values, <code>null</code> if null string input
      *
-     * @see StringEscapeUtils#escapeJavaScript(String)
+     * @see StringEscapeUtils#escapeEcmaScript(String)
      */
     public String javascript(Object string)
     {
@@ -296,7 +296,7 @@ public class EscapeTool extends SafeConf
     /**
      * Escapes the characters in a <code>String</code> using HTML entities.
      * <br />
-     * Delegates the process to {@link StringEscapeUtils#escapeHtml(String)}.
+     * Delegates the process to {@link StringEscapeUtils#escapeHtml4(String)}.
      *
      * @param string the string to escape, may be null
      * @return a new escaped <code>String</code>, <code>null</code>
if null string input
@@ -355,12 +355,11 @@ public class EscapeTool extends SafeConf
     /**
      * Escapes the characters in a <code>String</code> to be suitable to pass
to an SQL query.
      * <br />
-     * Delegates the process to {@link StringEscapeUtils#escapeSql(String)}.
+     * It boils down to doubling single quotes.
      *
      * @param string the string to escape, may be null
      * @return a new String, escaped for SQL, <code>null</code> if null string
input
      *
-     * @see StringEscapeUtils#escapeSql(String)
      */
     public String sql(Object string)
     {

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FieldTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
Mon Nov 14 22:40:07 2016
@@ -24,9 +24,6 @@ import java.lang.reflect.Modifier;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.tools.ClassUtils;
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
@@ -97,8 +94,6 @@ public class FieldTool extends SafeConfi
      */
     public static final String STORE_DYNAMIC_KEY = "storeDynamicLookups";
 
-    protected static Logger log = LoggerFactory.getLogger(FieldTool.class);
-    
     protected HashMap storage = new HashMap();
     protected boolean storeDynamicLookups = true;
 
@@ -258,7 +253,7 @@ public class FieldTool extends SafeConfi
      * in the specified {@link Class}. Returns {@code null} in case of failure.
      * 
      */
-    protected static Object retrieve(Field field, Class clazz)
+    protected Object retrieve(Field field, Class clazz)
     {
         try
         {
@@ -323,7 +318,7 @@ public class FieldTool extends SafeConfi
      * retrieval of the value of a field that is not final and may
      * change at different lookups.
      */
-    public static class MutableField
+    public class MutableField
     {
         private final Class clazz;
         private final Field field;
@@ -341,7 +336,7 @@ public class FieldTool extends SafeConfi
 
         public Object getValue()
         {
-            return FieldTool.retrieve(field, clazz);
+            return retrieve(field, clazz);
         }
     }
 

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
Mon Nov 14 22:40:07 2016
@@ -28,9 +28,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.ToolContext;
 import org.apache.velocity.tools.config.DefaultKey;
@@ -108,7 +105,6 @@ public class LinkTool extends SafeConfig
     public static final String CHARSET_KEY = "charset";
     public static final String XHTML_MODE_KEY = "xhtml";
 
-    protected static Logger LOG = LoggerFactory.getLogger(LinkTool.class);
     protected String scheme;
     protected String user;
     protected String host;
@@ -246,7 +242,7 @@ public class LinkTool extends SafeConfig
         catch (CloneNotSupportedException e)
         {
             String msg = "Could not properly clone " + getClass();
-            LOG.error(msg, e);
+            log.error(msg, e);
             throw new RuntimeException(msg, e);
         }
     }
@@ -353,7 +349,7 @@ public class LinkTool extends SafeConfig
             }
             catch (NumberFormatException nfe)
             {
-                LOG.error("Could not convert '{}' to int", obj, nfe);
+                log.error("Could not convert '{}' to int", obj, nfe);
                 this.port = -2; // use this to mean error
             }
         }
@@ -908,7 +904,7 @@ public class LinkTool extends SafeConfig
             }
             catch (Exception e)
             {
-                LOG.error("Could not convert '{}' to URI", obj, e);
+                log.error("Could not convert '{}' to URI", obj, e);
                 return null;
             }
         }
@@ -953,7 +949,7 @@ public class LinkTool extends SafeConfig
         }
         catch (Exception e)
         {
-            LOG.error("Could not create URI", e);
+            log.error("Could not create URI", e);
         }
         return null;
     }
@@ -1745,7 +1741,7 @@ public class LinkTool extends SafeConfig
         }
         catch (UnsupportedEncodingException uee)
         {
-            LOG.error("Character encoding '{}' is unsupported", charset, uee);
+            log.error("Character encoding '{}' is unsupported", charset, uee);
             return null;
         }
     }
@@ -1768,7 +1764,7 @@ public class LinkTool extends SafeConfig
         }
         catch (UnsupportedEncodingException uee)
         {
-            LOG.error("Character encoding '{}' is unsupported", charset, uee);
+            log.error("Character encoding '{}' is unsupported", charset, uee);
             return null;
         }
     }

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java
Mon Nov 14 22:40:07 2016
@@ -22,7 +22,6 @@ import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 
-import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
@@ -61,43 +60,41 @@ public class LogTool extends SafeConfig
 {
     public static final String LOGGER_NAME_KEY = "loggerName";
     
-    private Logger LOG = null;
-
     /**
      * configure the logger
      */
     protected void configure(ValueParser values)
     {
         String loggerName = values.getString(LOGGER_NAME_KEY);
-        if (loggerName == null)
+        if (loggerName != null)
         {
-            loggerName = "org.apache.velocity.tools";
+            /* override defaultly configured logger */
+            log = LoggerFactory.getLogger(loggerName);
         }
-        LOG = LoggerFactory.getLogger(loggerName);
     }
     
     public void error(String message)
     {
-        LOG.error(message);
+        log.error(message);
     }
 
     public void warn(String message)
     {
-        LOG.warn(message);
+        log.warn(message);
     }
 
     public void info(String message)
     {
-        LOG.info(message);
+        log.info(message);
     }
 
     public void debug(String message)
     {
-        LOG.debug(message);
+        log.debug(message);
     }
 
     public void trace(String message)
     {
-        LOG.trace(message);
+        log.trace(message);
     }
 }

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
Mon Nov 14 22:40:07 2016
@@ -32,9 +32,6 @@ import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * <p>
  * A convenience tool to use with #foreach loops. It wraps a list
@@ -95,14 +92,12 @@ import org.slf4j.LoggerFactory;
 
 @DefaultKey("loop")
 @ValidScope(Scope.REQUEST)
-public class LoopTool
+public class LoopTool extends SafeConfig
 {
     private Stack<ManagedIterator> iterators = new Stack<ManagedIterator>();
     private ManagedIterator last;
     private Map<String,Object> lastSyncedValues;
 
-    protected static Logger LOG = LoggerFactory.getLogger(LoopTool.class);
-    
     /**
      * <p>Tells the LoopTool to watch the specified Array, Collection, Map,
      * Iterator, Iterable, Enumeration or POJO with an iterator() method
@@ -581,7 +576,7 @@ public class LoopTool
      * escaping into the template.  In the case of such problems,
      * this will return {@code null}.
      */
-    protected static Iterator getIterator(Object obj)
+    protected Iterator getIterator(Object obj)
     {
         if (obj == null)
         {
@@ -593,7 +588,7 @@ public class LoopTool
         }
         catch (Exception e)
         {
-            LOG.error("Exception while getting Iterator:", e);
+            log.error("Exception while getting Iterator:", e);
         }
         return null;
     }
@@ -607,7 +602,7 @@ public class LoopTool
      * in order to have it automatically skip over or stop before
      * certain elements in the iterator.
      */
-    public static class ManagedIterator implements Iterator
+    public class ManagedIterator implements Iterator
     {
         private String name;
         private Iterator iterator;
@@ -952,7 +947,7 @@ public class LoopTool
          */
         public ManagedIterator sync(Object iterable, String name)
         {
-            Iterator parallel = LoopTool.getIterator(iterable);
+            Iterator parallel = getIterator(iterable);
             if (parallel == null)
             {
                 return null;

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/MarkupTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/MarkupTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/MarkupTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/MarkupTool.java
Mon Nov 14 22:40:07 2016
@@ -24,9 +24,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.tools.config.DefaultKey;
 
 /**
@@ -72,7 +69,6 @@ public class MarkupTool extends SafeConf
 
     private String tab = DEFAULT_TAB;
     private String delim = DEFAULT_DELIMITER;
-    private static Logger LOG = LoggerFactory.getLogger(MarkupTool.class);
 
     /**
      * Configuration
@@ -81,7 +77,7 @@ public class MarkupTool extends SafeConf
     {
         if (isConfigLocked())
         {
-            LOG.error("setTab() failure: configuration is locked");
+            log.error("setTab() failure: configuration is locked");
         }
         else
         {

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
Mon Nov 14 22:40:07 2016
@@ -21,9 +21,6 @@ package org.apache.velocity.tools.generi
 
 import java.io.StringWriter;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.app.VelocityEngine;
@@ -121,8 +118,6 @@ public class RenderTool extends SafeConf
 
     public static final String KEY_FORCE_THREAD_SAFE = "forceThreadSafe";
 
-    protected static Logger LOG = LoggerFactory.getLogger(RenderTool.class);
-    
     private VelocityEngine engine = null;
     private Context context;
     private int parseDepth = DEFAULT_PARSE_DEPTH;
@@ -181,7 +176,7 @@ public class RenderTool extends SafeConf
         }
         else if (this.parseDepth != depth)
         {
-            LOG.error("Attempt was made to alter parse depth while config was locked.");
+            log.error("Attempt was made to alter parse depth while config was locked.");
         }
     }
 
@@ -201,7 +196,7 @@ public class RenderTool extends SafeConf
         }
         else if (this.context != context)
         {
-            LOG.error("Attempt was made to set a new context while config was locked.");
+            log.error("Attempt was made to set a new context while config was locked.");
         }
     }
 
@@ -228,7 +223,7 @@ public class RenderTool extends SafeConf
         }
         else if (this.catchExceptions != catchExceptions)
         {
-            LOG.error("Attempt was made to alter catchE while config was locked.");
+            log.error("Attempt was made to alter catchE while config was locked.");
         }
     }
 
@@ -300,7 +295,7 @@ public class RenderTool extends SafeConf
             }
             catch (Exception e)
             {
-                LOG.error("evaluation failed:", e);
+                log.error("evaluation failed:", e);
                 return null;
             }
         }
@@ -371,7 +366,7 @@ public class RenderTool extends SafeConf
             else
             {
                 // abort, log and return what we have so far
-                LOG.error("recursion exceeded the maximum parse depth" +
+                log.error("recursion exceeded the maximum parse depth" +
                           " of {} on the following template: {}",
                           parseDepth, vtl);
                 return result;

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
Mon Nov 14 22:40:07 2016
@@ -19,6 +19,12 @@ package org.apache.velocity.tools.generi
  * under the License.
  */
 
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.tools.ToolContext;
+import org.apache.velocity.tools.config.ConfigurationUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.util.Map;
 
 /**
@@ -59,9 +65,22 @@ public class SafeConfig
      */
     public static final String SAFE_MODE_KEY = "safeMode";
 
+    /**
+     * Key used to explicitely specify the logger name
+     */
+    public static final String LOGGER_NAME_KEY = "loggerName";
+
+    /**
+     * Key used to specify whether or not tools shall use loggers
+     * named after the tools classes.
+     */
+    public static final String USE_CLASS_LOGGER_KEY = "useClassLogger";
+
     private boolean configLocked = false;
     private boolean safeMode = false;
 
+    protected Logger log = null;
+
     /**
      * Only allow subclass access to this.
      */
@@ -108,6 +127,11 @@ public class SafeConfig
         if (!isConfigLocked())
         {
             ValueParser values = new ValueParser(params);
+
+            // set up logger
+            initLogger(values);
+
+            // call configure
             configure(values);
 
             setSafeMode(values.getBoolean(SAFE_MODE_KEY, true));
@@ -129,4 +153,35 @@ public class SafeConfig
         // base implementation does nothing
     }
 
+    /**
+     * Initialize logger. Default implementation will try to get a Velocity engine
+     * from the configuration parameters, then try to use either the configured logger
+     * instance, or the configured logger name suffixed by 'tools.&lt;key&gt;'
+     * @param params configuration parameters
+     */
+    protected void initLogger(ValueParser params)
+    {
+        String loggerName = params.getString(LOGGER_NAME_KEY);
+        if (loggerName != null)
+        {
+            log = LoggerFactory.getLogger(loggerName);
+        }
+        else
+        {
+            boolean useClassLogger = params.getBoolean(USE_CLASS_LOGGER_KEY, false);
+            if (!useClassLogger)
+            {
+                VelocityEngine engine = (VelocityEngine) params.get(ToolContext.ENGINE_KEY);
+                String key = (String) params.get(ToolContext.TOOLKEY_KEY);
+                if (engine != null && key != null)
+                {
+                    log = ConfigurationUtils.getLog(engine, "tools." + key);
+                }
+            }
+            if (log == null)
+            {
+                log = LoggerFactory.getLogger(getClass());
+            }
+        }
+    }
 }

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SortTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SortTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SortTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SortTool.java
Mon Nov 14 22:40:07 2016
@@ -29,8 +29,6 @@ import java.util.Map;
 
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.velocity.tools.config.DefaultKey;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * SortTool allows a user to sort a collection (or array, iterator, etc)
@@ -116,10 +114,8 @@ import org.slf4j.LoggerFactory;
  * @version $Id$
  */
 @DefaultKey("sorter")
-public class SortTool
+public class SortTool extends SafeConfig
 {
-    protected static Logger LOG = LoggerFactory.getLogger(SortTool.class);
-    
     /**
      * Sorts a Collection using a Comparator. A defensive copy is made
      * of the Collection beforehand, so the original Collection is left
@@ -205,7 +201,7 @@ public class SortTool
         else
         {
             // the object type is not supported
-            LOG.error("object type not supported: {}", o == null ? "null" : o.getClass().getName());
+            log.error("object type not supported: {}", o == null ? "null" : o.getClass().getName());
             return null;
         }
     }
@@ -249,7 +245,7 @@ public class SortTool
             return sort((Map)object, properties);
         }
         // the object type is not supported
-        LOG.error("object type not supported: {}", object == null ? "null" : object.getClass().getName());
+        log.error("object type not supported: {}", object == null ? "null" : object.getClass().getName());
         return null;
     }
 
@@ -284,7 +280,7 @@ public class SortTool
         }
         catch (Exception e)
         {
-            LOG.error("exception encountered while sorting: {}", e.getMessage());
+            log.error("exception encountered while sorting: {}", e.getMessage());
             return null;
         }
     }

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
Mon Nov 14 22:40:07 2016
@@ -102,8 +102,6 @@ public class BrowserTool extends Browser
 {
     private static final long serialVersionUID = 1734529350532353339L;
 
-    protected static Logger LOG = LoggerFactory.getLogger(BrowserTool.class);
-
     /* User-Agent */
     private String userAgentString = null;
     private String lowercaseUserAgentString = null;
@@ -574,7 +572,7 @@ public class BrowserTool extends Browser
                     }
                     else
                     {
-                        LOG.error("BrowserTool: could not parse language quality value: {}",
language);
+                        log.error("BrowserTool: could not parse language quality value: {}",
language);
                     }
                 }
             }

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserToolDeprecatedMethods.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserToolDeprecatedMethods.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserToolDeprecatedMethods.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserToolDeprecatedMethods.java
Mon Nov 14 22:40:07 2016
@@ -7,6 +7,7 @@ import static org.apache.velocity.tools.
 @Deprecated
 public abstract class BrowserToolDeprecatedMethods extends FormatConfig
 {
+    public abstract String getUserAgentString();
     public abstract UAEntity getBrowser();
     public abstract UAEntity getRenderingEngine();
     public abstract UAEntity getOperatingSystem();
@@ -26,6 +27,15 @@ public abstract class BrowserToolDepreca
     protected abstract boolean test(String str);
 
     /**
+     * @deprecated use {@link #getBrowser()}.getUserAgentString()
+     */
+    @Deprecated
+    public String getUserAgent()
+    {
+        return getUserAgentString();
+    }
+    
+    /**
      * @deprecated use {@link #getBrowser()} version getters
      */
     @Deprecated

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java?rev=1769701&r1=1769700&r2=1769701&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
Mon Nov 14 22:40:07 2016
@@ -261,7 +261,7 @@ public class VelocityView extends ViewTo
         // (servletContext and factory should already be set by now
         if (this.velocity == null)
         {
-            this.velocity = new VelocityEngine();
+            setVelocityEngine(new VelocityEngine());
         }
 
         String allowOverwrite = config.findInitParameter(USER_OVERWRITE_KEY);
@@ -318,7 +318,7 @@ public class VelocityView extends ViewTo
     protected void configure(final JeeConfig config, final VelocityEngine velocity)
     {
         // first get the default properties, and bail if we don't find them
-	ExtProperties defaultProperties = getProperties(DEFAULT_PROPERTIES_PATH, true);
+        ExtProperties defaultProperties = getProperties(DEFAULT_PROPERTIES_PATH, true);
         velocity.setExtendedProperties(defaultProperties);
 
         // check for application-wide user props in the context init params
@@ -334,7 +334,16 @@ public class VelocityView extends ViewTo
 
         // check for a custom location for servlet-wide user props
         String servletPropsPath = config.getInitParameter(PROPERTIES_KEY);
-        setProps(velocity, servletPropsPath, true);
+        if (!USER_PROPERTIES_PATH.equals(servletPropsPath) && (appPropsPath == null
|| !appPropsPath.equals(servletPropsPath)))
+        {
+            setProps(velocity, servletPropsPath, true);
+        }
+
+        /* now that velocity engine is initialized, re-initialize our logger
+           so that it takes potentially provided configuration attributes
+           into account
+         */
+        initLog();
     }
 
     private boolean setProps(VelocityEngine velocity, String path, boolean require)
@@ -637,7 +646,7 @@ public class VelocityView extends ViewTo
     public Context render(HttpServletRequest request,
                           HttpServletResponse response) throws IOException
     {
-        // then get a context
+        // get a context
         Context context = createContext(request, response);
 
         // get the template
@@ -652,7 +661,7 @@ public class VelocityView extends ViewTo
     public Context render(HttpServletRequest request, Writer out)
         throws IOException
     {
-        // then get a context
+        // get a context
         Context context = createContext(request, null);
 
         // get the template




Mime
View raw message