aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2016-11-11 19:19:49 +0000
committerClaude Brisson <cbrisson@apache.org>2016-11-11 19:19:49 +0000
commit4d183e7d2c972796b8a22252a17d2f7b863d5d96 (patch)
tree7cce0d35194f76d22fd58013d9ab63c795361fac
parent01ebe9c07482c861a2a30f2fe2e0ce2b85182a2d (diff)
downloadapache-velocity-engine-4d183e7d2c972796b8a22252a17d2f7b863d5d96.tar.gz
[engine] Review logging:
- uses the base logger namespace 'org.apache.velocity' unless specified with runtime.log.name in the configuration - have the runtime instance log with this base namespace, and other modules log with children namespaces: x directive, and velocity.directive.[directivename] x parser x loader and loader.[loadername] x macro x rendering - get rid of UberspectLoggable interface - added new method RuntimeServices.getLog(childNamespace) (returns base + '.' + childNamespace, or the log instance if provided by runtime.log.instance) git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1769330 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java11
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java11
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java34
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java30
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java17
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java14
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java5
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader2.java5
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/DeprecatedCheckUberspector.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/SecureUberspector.java24
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java12
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectLoggable.java45
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectPublicFields.java20
-rw-r--r--velocity-engine-core/src/main/parser/Parser.jjt19
18 files changed, 143 insertions, 125 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java
index 0c71b5cc..a8a5f0b8 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java
@@ -20,10 +20,14 @@ package org.apache.velocity.app.event.implement;
*/
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.util.RuntimeServicesAware;
import org.apache.velocity.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.regex.PatternSyntaxException;
/**
@@ -58,6 +62,8 @@ public abstract class EscapeReference implements ReferenceInsertionEventHandler,
private String matchRegExp = null;
+ protected Logger log;
+
/**
* Escape the given text. Override this in a subclass to do the actual
* escaping.
@@ -115,6 +121,7 @@ public abstract class EscapeReference implements ReferenceInsertionEventHandler,
public void setRuntimeServices(RuntimeServices rs)
{
this.rs = rs;
+ log = rs.getLog("event");
// Get the regular expression pattern.
matchRegExp = StringUtils.nullTrim(rs.getConfiguration().getString(getMatchAttribute()));
@@ -132,8 +139,8 @@ public abstract class EscapeReference implements ReferenceInsertionEventHandler,
}
catch (PatternSyntaxException E)
{
- rs.getLog().error("Invalid regular expression '" + matchRegExp
- + "'. No escaping will be performed.", E);
+ log.error("Invalid regular expression '" + matchRegExp
+ + "'. No escaping will be performed.", E);
matchRegExp = null;
}
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
index 3d3dc434..fd1b5ee5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
@@ -21,11 +21,15 @@ package org.apache.velocity.app.event.implement;
import org.apache.velocity.app.event.IncludeEventHandler;
import org.apache.velocity.context.Context;
+import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.util.ContextAware;
import org.apache.velocity.util.RuntimeServicesAware;
import org.apache.velocity.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Simple event handler that checks to see if an included page is available.
* If not, it includes a designated replacement page instead.
@@ -49,7 +53,7 @@ import org.apache.velocity.util.StringUtils;
* @version $Id$
* @since 1.5
*/
-public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware,ContextAware {
+public class IncludeNotFound implements IncludeEventHandler, RuntimeServicesAware, ContextAware {
private static final String DEFAULT_NOT_FOUND = "notfound.vm";
private static final String PROPERTY_NOT_FOUND = "eventhandler.include.notfound";
@@ -57,6 +61,8 @@ public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware
String notfound;
Context context;
+ protected Logger log;
+
/**
* Check to see if included file exists, and display "not found" page if it
* doesn't. If "not found" page does not exist, log an error and return
@@ -89,7 +95,7 @@ public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware
/**
* can't find not found, so display nothing
*/
- rs.getLog().error("Can't find include not found page: " + notfound);
+ log.error("Can't find include not found page: " + notfound);
return null;
}
}
@@ -104,6 +110,7 @@ public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware
public void setRuntimeServices(RuntimeServices rs)
{
this.rs = rs;
+ log = rs.getLog("event");
notfound = StringUtils.nullTrim(rs.getString(PROPERTY_NOT_FOUND, DEFAULT_NOT_FOUND));
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
index 050cb258..19053192 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
@@ -50,16 +50,6 @@ public interface RuntimeConstants
/** externally provided logger name. */
String RUNTIME_LOG_NAME = "runtime.log.name";
- /**
- * Properties referenced in the template are required to exist the object
- */
- String RUNTIME_REFERENCES_STRICT = "runtime.references.strict";
-
- /**
- * Indicates we are going to use modified escape behavior in strict mode
- */
- String RUNTIME_REFERENCES_STRICT_ESCAPE = "runtime.references.strict.escape";
-
/** Logging of invalid references. */
String RUNTIME_LOG_REFERENCE_LOG_INVALID = "runtime.log.invalid.references";
@@ -230,7 +220,23 @@ public interface RuntimeConstants
* @since 1.7
*/
String VM_BODY_REFERENCE = "velocimacro.body.reference";
-
+
+ /*
+ * ----------------------------------------------------------------------
+ * S T I C T M O D E B E H A V I O U R
+ * ----------------------------------------------------------------------
+ */
+
+ /**
+ * Properties referenced in the template are required to exist the object
+ */
+ String RUNTIME_REFERENCES_STRICT = "runtime.references.strict";
+
+ /**
+ * Indicates we are going to use modified escape behavior in strict mode
+ */
+ String RUNTIME_REFERENCES_STRICT_ESCAPE = "runtime.references.strict.escape";
+
/*
* ----------------------------------------------------------------------
* G E N E R A L R U N T I M E C O N F I G U R A T I O N
@@ -302,6 +308,12 @@ public interface RuntimeConstants
/** Default Runtime properties. */
String DEFAULT_RUNTIME_DIRECTIVES = "org/apache/velocity/runtime/defaults/directive.properties";
+ /** externally provided logger name. */
+ String DEFAULT_RUNTIME_LOG_NAME = "org.apache.velocity";
+
+ /** token used to identify the loader internally. */
+ String RESOURCE_LOADER_IDENTIFIER = "_RESOURCE_LOADER_IDENTIFIER_";
+
/**
* The default number of parser instances to create. Configurable via the parameter named by the {@link #PARSER_POOL_SIZE}
* constant.
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 f2c3fb29..a9329ae4 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
@@ -51,7 +51,6 @@ import org.apache.velocity.util.StringUtils;
import org.apache.velocity.util.introspection.ChainableUberspector;
import org.apache.velocity.util.introspection.LinkingUberspector;
import org.apache.velocity.util.introspection.Uberspect;
-import org.apache.velocity.util.introspection.UberspectLoggable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -109,9 +108,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
private VelocimacroFactory vmFactory = null;
/**
- * The Runtime logger. The default instance is the "Velocity" logger.
+ * The Runtime logger. The default instance is the "org.apache.velocity" logger.
*/
- private Logger log = LoggerFactory.getLogger("Velocity");
+ private Logger log = LoggerFactory.getLogger(DEFAULT_RUNTIME_LOG_NAME);
/**
* The Runtime parser pool
@@ -328,7 +327,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
}
catch (Exception e)
{
- getLog().error("Could not auto-initialize Velocity", e);
+ log.error("Could not auto-initialize Velocity", e);
throw new RuntimeException("Velocity could not be initialized!", e);
}
}
@@ -398,11 +397,6 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
Uberspect u = (Uberspect)o;
- if (u instanceof UberspectLoggable)
- {
- ((UberspectLoggable)u).setLog(getLog());
- }
-
if (u instanceof RuntimeServicesAware)
{
((RuntimeServicesAware)u).setRuntimeServices(this);
@@ -1696,6 +1690,24 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
}
/**
+ * Get a logger for the specified child namespace.
+ * If a logger was configured using the runtime.log.instance configuration property, returns this instance.
+ * Otherwise, uses SLF4J LoggerFactory on baseNamespace + childNamespace.
+ * @param childNamespace
+ * @return
+ */
+ public Logger getLog(String childNamespace)
+ {
+ Logger log = (Logger)getProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE);
+ if (log == null)
+ {
+ String loggerName = getString(RUNTIME_LOG_NAME, DEFAULT_RUNTIME_LOG_NAME) + "." + childNamespace;
+ log = LoggerFactory.getLogger(loggerName);
+ }
+ return log;
+ }
+
+ /**
* String property accessor method with default to hide the
* configuration implementation.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
index 09057650..76279f78 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
@@ -440,6 +440,15 @@ public interface RuntimeServices
public Logger getLog();
/**
+ * Get a logger for the specified child namespace.
+ * If a logger was configured using the runtime.log.instance configuration property, returns this instance.
+ * Otherwise, uses SLF4J LoggerFactory on baseNamespace + childNamespace.
+ * @param childNamespace
+ * @return
+ */
+ public Logger getLog(String childNamespace);
+
+ /**
* Returns the event handlers for the application.
* @return The event handlers for the application.
*/
@@ -465,7 +474,15 @@ public interface RuntimeServices
*/
public Directive getDirective(String name);
+ /**
+ * Check whether the engine uses string interning
+ * @return true if string interning is active
+ */
public boolean useStringInterning();
+ /**
+ * get space gobbling mode
+ * @return space gobbling mode
+ */
public SpaceGobbling getSpaceGobbling();
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
index fdf2a085..a66656f5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
@@ -26,7 +26,9 @@ import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.directive.Macro;
import org.apache.velocity.runtime.directive.VelocimacroProxy;
import org.apache.velocity.runtime.parser.node.Node;
+
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
@@ -104,7 +106,7 @@ public class VelocimacroFactory
public VelocimacroFactory(final RuntimeServices rsvc)
{
this.rsvc = rsvc;
- this.log = rsvc.getLog();
+ this.log = rsvc.getLog("macro");
/*
* we always access in a synchronized(), so we
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
index 13c783ff..238871b5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
@@ -31,11 +31,13 @@ import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
-
/**
* Base class for all directives used in Velocity.
*
@@ -50,6 +52,8 @@ public abstract class Directive implements DirectiveConstants, Cloneable
private boolean provideScope = false;
private Template template;
+ protected Logger log = null;
+
/**
*
*/
@@ -155,6 +159,7 @@ public abstract class Directive implements DirectiveConstants, Cloneable
throws TemplateInitException
{
rsvc = rs;
+ log = rsvc.getLog("directive." + getName());
String property = getScopeName()+'.'+RuntimeConstants.PROVIDE_SCOPE_CONTROL;
this.provideScope = rsvc.getBoolean(property, provideScope);
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
index b797b870..dc5d9232 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
@@ -25,15 +25,17 @@ import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.util.StringUtils;
+
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.Writer;
-import java.util.Arrays;
/**
*
@@ -332,7 +334,7 @@ public class SimpleNode implements Node
*/
rsvc = (RuntimeServices) data;
- log = rsvc.getLog();
+ log = rsvc.getLog("rendering");
int i, k = jjtGetNumChildren();
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
index 7dc5af8f..73e29b1c 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
@@ -30,6 +30,7 @@ import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.ExtProperties;
import org.apache.velocity.util.StringUtils;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
@@ -57,9 +58,6 @@ public class ResourceManagerImpl
/** A static content resource. */
public static final int RESOURCE_CONTENT = 2;
- /** token used to identify the loader internally. */
- private static final String RESOURCE_LOADER_IDENTIFIER = "_RESOURCE_LOADER_IDENTIFIER_";
-
/** Object implementing ResourceCache to be our resource manager's Resource cache. */
protected ResourceCache globalCache = null;
@@ -93,7 +91,7 @@ public class ResourceManagerImpl
*
* @param rsvc The Runtime Services object which is associated with this Resource Manager.
*/
- public synchronized void initialize(final RuntimeServices rsvc)
+ public synchronized void initialize(final RuntimeServices rs)
{
if (isInit)
{
@@ -103,8 +101,8 @@ public class ResourceManagerImpl
ResourceLoader2 resourceLoader = null;
- this.rsvc = rsvc;
- log = rsvc.getLog();
+ rsvc = rs;
+ log = rsvc.getLog("loader");
log.trace("ResourceManager initializing: {}", this.getClass());
@@ -132,7 +130,7 @@ public class ResourceManagerImpl
else
{
String msg = "Unable to find '" +
- configuration.getString(RESOURCE_LOADER_IDENTIFIER) +
+ configuration.getString(RuntimeConstants.RESOURCE_LOADER_IDENTIFIER) +
".resource.loader.class' specification in configuration." +
" This is a critical value. Please adjust configuration.";
log.error(msg);
@@ -250,7 +248,7 @@ public class ResourceManagerImpl
* in the 'name' field
*/
- loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName);
+ loaderConfiguration.setProperty(RuntimeConstants.RESOURCE_LOADER_IDENTIFIER, loaderName);
/*
* Add resources to the list of resource loader
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
index f66c54f8..8a44012a 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
@@ -23,6 +23,7 @@ import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeServices;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -51,9 +52,9 @@ public class JarHolder
* @param rs
* @param urlpath
*/
- public JarHolder( RuntimeServices rs, String urlpath )
+ public JarHolder( RuntimeServices rs, String urlpath, Logger log )
{
- this.log = rs.getLog();
+ this.log = log;
this.urlpath=urlpath;
init();
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
index 5a2064a4..ea60d5a9 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
@@ -137,7 +137,7 @@ public class JarResourceLoader extends ResourceLoader2
closeJar( path );
// Create a new JarHolder
- JarHolder temp = new JarHolder( rsvc, path );
+ JarHolder temp = new JarHolder( rsvc, path, log );
// Add it's entries to the entryCollection
addEntries(temp.getEntries());
// Add it to the Jar table
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader2.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader2.java
index 118e2af0..dbeb9613 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader2.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader2.java
@@ -27,7 +27,9 @@ import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.ResourceCacheImpl;
import org.apache.velocity.util.ExtProperties;
+
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -78,7 +80,8 @@ public abstract class ResourceLoader2
public void commonInit(RuntimeServices rs, ExtProperties configuration)
{
this.rsvc = rs;
- this.log = rsvc.getLog();
+ String loaderName = configuration.getString(RuntimeConstants.RESOURCE_LOADER_IDENTIFIER);
+ log = rsvc.getLog("loader." + (loaderName == null ? this.getClass().getSimpleName() : loaderName));
/*
* these two properties are not required for all loaders.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/DeprecatedCheckUberspector.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/DeprecatedCheckUberspector.java
index 88a6cfd7..e93ab66d 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/DeprecatedCheckUberspector.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/DeprecatedCheckUberspector.java
@@ -33,7 +33,7 @@ import java.lang.reflect.Method;
* @version $Id:$
* @see ChainableUberspector
*/
-public class DeprecatedCheckUberspector extends AbstractChainableUberspector implements Uberspect, UberspectLoggable
+public class DeprecatedCheckUberspector extends AbstractChainableUberspector implements Uberspect
{
@Override
public void init()
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/SecureUberspector.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/SecureUberspector.java
index 690dab2c..06bedb7e 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/SecureUberspector.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/SecureUberspector.java
@@ -40,15 +40,8 @@ import java.util.Iterator;
* @version $Id$
* @since 1.5
*/
-public class SecureUberspector extends UberspectImpl implements RuntimeServicesAware
+public class SecureUberspector extends UberspectImpl
{
- RuntimeServices runtimeServices;
-
- public SecureUberspector()
- {
- super();
- }
-
/**
* init - generates the Introspector. As the setup code
* makes sure that the log gets set before this is called,
@@ -56,10 +49,10 @@ public class SecureUberspector extends UberspectImpl implements RuntimeServicesA
*/
public void init()
{
- String [] badPackages = runtimeServices.getConfiguration()
+ String [] badPackages = rsvc.getConfiguration()
.getStringArray(RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES);
- String [] badClasses = runtimeServices.getConfiguration()
+ String [] badClasses = rsvc.getConfiguration()
.getStringArray(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES);
introspector = new SecureIntrospectorImpl(badClasses, badPackages, log);
@@ -89,15 +82,4 @@ public class SecureUberspector extends UberspectImpl implements RuntimeServicesA
}
return null;
}
-
- /**
- * Store the RuntimeServices before the object is initialized..
- * @param rs RuntimeServices object for initialization
- */
- public void setRuntimeServices(RuntimeServices rs)
- {
- this.runtimeServices = rs;
- }
-
-
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java
index ab61547c..8edea3f3 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java
@@ -38,6 +38,7 @@ import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.EnumerationIterator;
import org.apache.velocity.util.RuntimeServicesAware;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
@@ -54,7 +55,7 @@ import java.util.Map;
* @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class UberspectImpl implements Uberspect, UberspectLoggable, RuntimeServicesAware
+public class UberspectImpl implements Uberspect, RuntimeServicesAware
{
/**
* Our runtime logger.
@@ -72,6 +73,11 @@ public class UberspectImpl implements Uberspect, UberspectLoggable, RuntimeServi
protected ConversionHandler conversionHandler;
/**
+ * runtime services
+ */
+ protected RuntimeServices rsvc;
+
+ /**
* init - generates the Introspector. As the setup code
* makes sure that the log gets set before this is called,
* we can initialize the Introspector using the log object.
@@ -92,6 +98,9 @@ public class UberspectImpl implements Uberspect, UberspectLoggable, RuntimeServi
*/
public void setRuntimeServices(RuntimeServices rs)
{
+ rsvc = rs;
+ log = rsvc.getLog("rendering");
+
String conversionHandlerClass = rs.getString(RuntimeConstants.CONVERSION_HANDLER_CLASS);
if (conversionHandlerClass == null || conversionHandlerClass.equals("none"))
{
@@ -141,6 +150,7 @@ public class UberspectImpl implements Uberspect, UberspectLoggable, RuntimeServi
*
* @param log The logger instance to use.
* @since 1.5
+ * @Deprecated logger is now set by default to the namespace logger "velocity.rendering".
*/
public void setLog(Logger log)
{
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectLoggable.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectLoggable.java
deleted file mode 100644
index 5531aa67..00000000
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectLoggable.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.velocity.util.introspection;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.slf4j.Logger;
-
-/**
- * Marker interface to let an uberspector indicate it can and wants to
- * log
- *
- * Thanks to Paulo for the suggestion
- *
- * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id$
- *
- */
-public interface UberspectLoggable
-{
-
- /**
- * Sets the logger. This will be called before any calls to the
- * uberspector
- * @param log
- */
- public void setLog(Logger log);
-
-}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectPublicFields.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectPublicFields.java
index c00f51dd..a441799e 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectPublicFields.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectPublicFields.java
@@ -19,8 +19,10 @@
package org.apache.velocity.util.introspection;
+import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.PublicFieldExecutor;
import org.apache.velocity.runtime.parser.node.SetPublicFieldExecutor;
+import org.apache.velocity.util.RuntimeServicesAware;
import org.apache.velocity.util.introspection.UberspectImpl.VelGetterImpl;
import org.apache.velocity.util.introspection.UberspectImpl.VelSetterImpl;
import org.slf4j.Logger;
@@ -34,7 +36,7 @@ import java.util.Iterator;
* @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
* @author <a href="mailto:cdauth@cdauth.eu">Candid Dauth</a>
*/
-public class UberspectPublicFields implements Uberspect, UberspectLoggable
+public class UberspectPublicFields implements Uberspect, RuntimeServicesAware
{
/**
* Our runtime logger.
@@ -57,18 +59,6 @@ public class UberspectPublicFields implements Uberspect, UberspectLoggable
}
/**
- * Sets the runtime logger - this must be called before anything
- * else.
- *
- * @param log The logger instance to use.
- * @since 1.5
- */
- public void setLog(Logger log)
- {
- this.log = log;
- }
-
- /**
* Property getter
* @param obj
* @param identifier
@@ -123,4 +113,8 @@ public class UberspectPublicFields implements Uberspect, UberspectLoggable
return null;
}
+ public void setRuntimeServices(RuntimeServices rs)
+ {
+ log = rs.getLog("rendering");
+ }
}
diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt
index 89398848..6e8df9fd 100644
--- a/velocity-engine-core/src/main/parser/Parser.jjt
+++ b/velocity-engine-core/src/main/parser/Parser.jjt
@@ -88,6 +88,8 @@ import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.directive.MacroParseException;
import org.apache.velocity.runtime.RuntimeConstants;
+import org.slf4j.Logger;
+
/**
* This class is responsible for parsing a Velocity
* template. This class was generated by JavaCC using
@@ -124,6 +126,8 @@ public class Parser
private RuntimeServices rsvc = null;
+ private Logger log = null;
+
/**
* This constructor was added to allow the re-use of parsers.
* The normal constructor takes a single argument which
@@ -141,6 +145,13 @@ public class Parser
new ByteArrayInputStream("\n".getBytes()), 1, 1 ));
/*
+ * then initialize logger
+ */
+
+ log = rs.getLog("parser");
+
+
+ /*
* now setup a VCS for later use
*/
velcharstream = new VelocityCharStream(
@@ -198,12 +209,12 @@ public class Parser
* thrown by the Macro class when something is amiss in the
* Macro specification
*/
- rsvc.getLog().error("Parser Error: " + template.getName(), mee);
+ log.error("{}: {}", template.getName(), mee.getMessage(), mee);
throw mee;
}
catch (ParseException pe)
{
- rsvc.getLog().error("Parser Exception: " + template.getName(), pe);
+ log.error("{}: {}", currentTemplate.getName(), pe.getMessage(), pe);
throw new TemplateParseException (pe.currentToken,
pe.expectedTokenSequences, pe.tokenImage, currentTemplate.getName());
}
@@ -213,8 +224,8 @@ public class Parser
}
catch (Exception e)
{
- String msg = "Parser Error: " + template.getName();
- rsvc.getLog().error(msg, e);
+ String msg = template.getName() + ": " + e.getMessage();
+ log.error(msg, e);
throw new VelocityException(msg, e);
}