diff options
12 files changed, 57 insertions, 43 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java index fc27fdb2..73b22592 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java @@ -33,6 +33,7 @@ import org.apache.velocity.runtime.parser.ParseException; import org.apache.velocity.runtime.parser.node.SimpleNode; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.runtime.resource.ResourceManager; +import org.slf4j.Logger; import java.io.BufferedReader; import java.io.IOException; @@ -324,7 +325,7 @@ public class Template extends Resource /* * the macro lib wasn't found. Note it and throw */ - rsvc.getLog().error("template.merge(): " + + log.error("template.merge(): " + "cannot find template " + (String) macroLibraries.get(i)); throw re; @@ -335,9 +336,9 @@ public class Template extends Resource * the macro lib was found, but didn't parse - syntax error * note it and throw */ - rsvc.getLog().error("template.merge(): " + + rsvc.getLog("parser").error("template.merge(): " + "syntax error in template " + - (String) macroLibraries.get(i) + "."); + (String) macroLibraries.get(i) + ": {}", pe.getMessage(), pe); throw pe; } @@ -366,9 +367,13 @@ public class Template extends Resource { throw stop; } - else if (rsvc.getLog().isDebugEnabled()) + else { - rsvc.getLog().debug(stop.getMessage()); + Logger renderingLog = rsvc.getLog("rendering"); + if (renderingLog.isDebugEnabled()) + { + renderingLog.debug(stop.getMessage()); + } } } catch (IOException e) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java index e007d826..d3ddf408 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java @@ -22,6 +22,7 @@ package org.apache.velocity.runtime; import org.apache.velocity.runtime.parser.CharStream; import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.util.SimplePool; +import org.slf4j.Logger; /** * This wraps the original parser SimplePool class. It also handles @@ -35,6 +36,7 @@ public class ParserPoolImpl implements ParserPool { SimplePool pool = null; int max = RuntimeConstants.NUMBER_OF_PARSERS; + Logger log; /** * Create the underlying "pool". @@ -42,6 +44,7 @@ public class ParserPoolImpl implements ParserPool { */ public void initialize(RuntimeServices rsvc) { + log = rsvc.getLog("parser"); max = rsvc.getInt(RuntimeConstants.PARSER_POOL_SIZE, RuntimeConstants.NUMBER_OF_PARSERS); pool = new SimplePool(max); @@ -50,9 +53,9 @@ public class ParserPoolImpl implements ParserPool { pool.put(rsvc.createNewParser()); } - if (rsvc.getLog().isDebugEnabled()) + if (log.isDebugEnabled()) { - rsvc.getLog().debug("Created '" + max + "' parsers."); + log.debug("Created '" + max + "' parsers."); } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java index a9329ae4..d9f9c689 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java @@ -1428,7 +1428,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices catch(Exception e) { String msg = "RuntimeInstance.render(): init exception for tag = "+logTag; - getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } @@ -1452,9 +1452,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices { throw stop; } - else if (getLog().isDebugEnabled()) + else if (log.isDebugEnabled()) { - getLog().debug(stop.getMessage()); + log.debug(stop.getMessage()); } } catch (IOException e) @@ -1517,7 +1517,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices if (vmName == null || context == null || writer == null) { String msg = "RuntimeInstance.invokeVelocimacro() : invalid call : vmName, context, and writer must not be null"; - getLog().error(msg); + log.error(msg); throw new NullPointerException(msg); } @@ -1536,7 +1536,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices { String msg = "RuntimeInstance.invokeVelocimacro() : VM '" + vmName + "' is not registered."; - getLog().error(msg); + log.error(msg); throw new VelocityException(msg); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java index 56b105e3..3675a011 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java @@ -187,7 +187,7 @@ public class Foreach extends Directive { String msg = "Error getting iterator for #foreach parameter " + node.literal() + " at " + StringUtils.formatFileString(node); - rsvc.getLog().error(msg, ee); + log.error(msg, ee); throw new VelocityException(msg, ee); } @@ -196,7 +196,7 @@ public class Foreach extends Directive String msg = "#foreach parameter " + node.literal() + " at " + StringUtils.formatFileString(node) + " is of type " + iterable.getClass().getName() + " and cannot be iterated by " + rsvc.getUberspect().getClass().getName(); - rsvc.getLog().error(msg); + log.error(msg); throw new VelocityException(msg); } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java index ef59e2e5..8a05d622 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java @@ -169,7 +169,7 @@ public class Include extends InputBase { String msg = "invalid #include() argument '" + n.toString() + "' at " + StringUtils.formatFileString(this); - rsvc.getLog().error(msg); + log.error(msg); outputErrorToStream( writer, "error with arg " + i + " please see log."); throw new VelocityException(msg); @@ -197,7 +197,7 @@ public class Include extends InputBase { if ( node == null ) { - rsvc.getLog().error("#include() null argument"); + log.error("#include() null argument"); return false; } @@ -207,7 +207,7 @@ public class Include extends InputBase Object value = node.value( context ); if ( value == null) { - rsvc.getLog().error("#include() null argument"); + log.error("#include() null argument"); return false; } @@ -242,7 +242,7 @@ public class Include extends InputBase /* * the arg wasn't found. Note it and throw */ - rsvc.getLog().error("#include(): cannot find resource '" + arg + + log.error("#include(): cannot find resource '" + arg + "', called at " + StringUtils.formatFileString(this)); throw rnfe; } @@ -252,7 +252,7 @@ public class Include extends InputBase */ catch( RuntimeException e ) { - rsvc.getLog().error("#include(): arg = '" + arg + + log.error("#include(): arg = '" + arg + "', called at " + StringUtils.formatFileString(this)); throw e; } @@ -260,7 +260,7 @@ public class Include extends InputBase { String msg = "#include(): arg = '" + arg + "', called at " + StringUtils.formatFileString(this); - rsvc.getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java index 7da0ae42..2f563926 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java @@ -231,8 +231,7 @@ public class Macro extends Directive StringBuffer msg = new StringBuffer("Macro.getArgArray() : nbrArgs="); msg.append(numArgs).append(" : "); macroToString(msg, macroArgs); - rsvc.getLog().debug(msg.toString()); - System.out.println("---- > macro: " + msg); + rsvc.getLog("macro").debug(msg.toString()); } return macroArgs; diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java index b440d201..a6da07dd 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java @@ -149,9 +149,9 @@ public class Parse extends InputBase * does it have a value? If you have a null reference, then no. */ Object value = node.jjtGetChild(0).value( context ); - if (value == null && rsvc.getLog().isDebugEnabled()) + if (value == null && log.isDebugEnabled()) { - rsvc.getLog().debug("#parse(): null argument at " + + log.debug("#parse(): null argument at " + StringUtils.formatFileString(this)); } @@ -198,7 +198,7 @@ public class Parse extends InputBase { path.append( " > " + templateStack[i] ); } - rsvc.getLog().error("Max recursion depth reached (" + + log.error("Max recursion depth reached (" + templateStack.length + ')' + " File stack:" + path); return false; @@ -220,7 +220,7 @@ public class Parse extends InputBase /* * the arg wasn't found. Note it and throw */ - rsvc.getLog().error("#parse(): cannot find template '" + arg + + log.error("#parse(): cannot find template '" + arg + "', called at " + StringUtils.formatFileString(this)); throw rnfe; } @@ -230,7 +230,7 @@ public class Parse extends InputBase * the arg was found, but didn't parse - syntax error * note it and throw */ - rsvc.getLog().error("#parse(): syntax error in #parse()-ed template '" + log.error("#parse(): syntax error in #parse()-ed template '" + arg + "', called at " + StringUtils.formatFileString(this)); throw pee; } @@ -239,7 +239,7 @@ public class Parse extends InputBase */ catch( RuntimeException e ) { - rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " + + log.error("Exception rendering #parse(" + arg + ") at " + StringUtils.formatFileString(this)); throw e; } @@ -247,7 +247,7 @@ public class Parse extends InputBase { String msg = "Exception rendering #parse(" + arg + ") at " + StringUtils.formatFileString(this); - rsvc.getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } @@ -294,7 +294,7 @@ public class Parse extends InputBase /** * Log #parse errors so the user can track which file called which. */ - rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " + + log.error("Exception rendering #parse(" + arg + ") at " + StringUtils.formatFileString(this)); throw e; } @@ -302,7 +302,7 @@ public class Parse extends InputBase { String msg = "Exception rendering #parse(" + arg + ") at " + StringUtils.formatFileString(this); - rsvc.getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } finally diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java index 1e67763e..3d2ce82f 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java @@ -342,13 +342,13 @@ public class RuntimeMacro extends Directive * especially important for multiple macro call levels. * this is also true for the following catch blocks. */ - rsvc.getLog().error("Exception in macro #" + macroName + " called at " + + log.error("Exception in macro #" + macroName + " called at " + StringUtils.formatFileString(node)); throw e; } catch (IOException e) { - rsvc.getLog().error("Exception in macro #" + macroName + " called at " + + log.error("Exception in macro #" + macroName + " called at " + StringUtils.formatFileString(node)); throw e; } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java index a5503533..9acafa68 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java @@ -137,7 +137,8 @@ public class VelocimacroProxy extends Directive */ public void init(RuntimeServices rs) { - rsvc = rs; // CB TODO - why not super.init(rs) ? + rsvc = rs; + log = rs.getLog("macro"); // this is a very expensive call (ExtendedProperties is very slow) strictArguments = rsvc.getConfiguration().getBoolean( @@ -202,7 +203,7 @@ public class VelocimacroProxy extends Directive catch (Exception e) { String msg = "VelocimacroProxy.render() : exception VM = #" + macroName + "()"; - rsvc.getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } finally @@ -256,10 +257,10 @@ public class VelocimacroProxy extends Directive + macroArgs.get(0).name + " accepts at most " + (macroArgs.size()-1) + " at " + StringUtils.formatFileString(node)); } - else if (rsvc.getLog().isDebugEnabled()) + else if (log.isDebugEnabled()) { // Backward compatibility logging, Mainly for MacroForwardDefinedTestCase - rsvc.getLog().debug("VM #" + macroArgs.get(0).name + log.debug("VM #" + macroArgs.get(0).name + ": too many arguments to macro. Wanted " + (macroArgs.size()-1) + " got " + callArgNum); } @@ -289,7 +290,7 @@ public class VelocimacroProxy extends Directive out.append(stack[i]); } out.append(" at " + StringUtils.formatFileString(this)); - rsvc.getLog().error(out.toString()); + log.error(out.toString()); // clean out the macro stack, since we just broke it while (context.getCurrentMacroCallDepth() > 0) @@ -346,9 +347,9 @@ public class VelocimacroProxy extends Directive else { // Backward compatibility logging, Mainly for MacroForwardDefinedTestCase - if (rsvc.getLog().isDebugEnabled()) + if (log.isDebugEnabled()) { - rsvc.getLog().debug("VM #" + macroArgs.get(0).name + log.debug("VM #" + macroArgs.get(0).name + ": too few arguments to macro. Wanted " + (macroArgs.size()-1) + " got " + callArgNum); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java index 6b6c172d..7976fb4f 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java @@ -83,7 +83,7 @@ public class ContentResource extends Resource catch ( Exception e ) { String msg = "Cannot process content resource"; - rsvc.getLog().error(msg, e); + log.error(msg, e); throw new VelocityException(msg, e); } finally diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java index ec49e7fa..e1fa0ed4 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java @@ -24,6 +24,7 @@ import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.RuntimeServices; import org.apache.velocity.runtime.resource.loader.ResourceLoader2; +import org.slf4j.Logger; /** * This class represent a general text resource that @@ -37,6 +38,7 @@ import org.apache.velocity.runtime.resource.loader.ResourceLoader2; public abstract class Resource { protected RuntimeServices rsvc = null; + protected Logger log = null; /** * The template loader that initially loaded the input @@ -100,6 +102,7 @@ public abstract class Resource public void setRuntimeServices( RuntimeServices rs ) { rsvc = rs; + log = rsvc.getLog("loader"); } /** diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java index 87f9fcee..a1d19f32 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java @@ -21,6 +21,7 @@ package org.apache.velocity.runtime.resource; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.RuntimeServices; +import org.slf4j.Logger; import java.util.Collections; import java.util.Iterator; @@ -95,6 +96,8 @@ public class ResourceCacheImpl implements ResourceCache */ protected RuntimeServices rsvc = null; + protected Logger log; + /** * @see org.apache.velocity.runtime.resource.ResourceCache#initialize(org.apache.velocity.runtime.RuntimeServices) */ @@ -112,8 +115,8 @@ public class ResourceCacheImpl implements ResourceCache lruCache.putAll(cache); cache = lruCache; } - rsvc.getLog().debug("ResourceCache: initialized ("+this.getClass()+") with "+ - cache.getClass()+" cache map."); + rsvc.getLog().debug("initialized (" + this.getClass() + ") with " + + cache.getClass() + " cache map."); } /** |