Reputation: 2216
I am trying to initialize VelocityEngine
but getting exception on .init()
call:
org.apache.velocity.exception.VelocityException: The specified logger
class org.apache.velocity.runtime.log.AvalonLogChute does not
implement the org.apache.velocity.runtime.log.LogChute interface.
My code looks like:
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(....) //I do not change logging properties
...
velocityEngine.init();
There is no second velocity jar in dependency tree. But there is apache-click jar, which, from what I see, contains it's own Velocity implementation or at least part of it.
So it looks like classloader problem. I found temporary solution here: https://plus.google.com/116012605255269201011/posts/6tviyMPbqTU
But I wonder if there is any way to solve this problem without substituting thread classloader.
Upvotes: 0
Views: 1698
Reputation: 58792
Inside click jar you have velocity.properties org\apache\velocity\runtime\defaults\
You can configure logging in 3 ways:
Existing Log4j Logger
Starting with version 1.3, Velocity will log its output to an existing Log4j Logger setup elsewhere in the application. To use this feature you must Make sure that the Log4j jar is in your classpath. (You would do this anyway since you are using Log4j in the application using Velocity.) Configure Velocity to use the Log4JLogChute class by specifying the name of the existing Logger to use via the 'runtime.log.logsystem.log4j.logger' property. Note that this support for Logger is in version 1.5 of Velocity. Further, in version 1.5 we removed the now-ancient and very deprecated original Log4JLogSystem class and replaced with the current Log4JLogChute class which uses the Logger class. We apologize for the confusion, but we needed to move on.
Custom Standalone Logger
You can create a custom logging class - you just need to implement the interface org.apache.velocity.runtime.log.LogChute and then simply set the configuration property runtime.log.logsystem.class with the classname, and Velocity will create an instance of that class at init time. You may specify the classname as you specify any other properties. See the information on the Velocity helper class as well as the configuration keys and values. Please note that the old org.apache.velocity.runtime.log.LogSystem interface has been deprecated for v1.5 in favor of the new LogChute interface. This is due to significant upgrades to our logging code that could not be supported by the LogSystem interface. But don't worry, if you specify a custom class that implements the LogSystem interface, it will still work. However, it will generate deprecation warnings. You should upgrade your custom logger to implement LogChute as soon as possible.
Integrated Logging
You can integrate Velocity's logging capabilities with your applications existing logging system, simply by implementing the org.apache.velocity.runtime.log.LogChute interface. Then, pass an instance of your logging class to Velocity via the runtime.log.logsystem configuration key before initializing the Velocity engine, and Velocity will log messages to your application's logger. See the information on the Velocity helper class as well as the configuration keys and values.
Current runtime log:
runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogChute,org.apache.velocity.runtime.log.Log4JLogChute,org.apache.velocity.runtime.log.CommonsLogLogChute,org.apache.velocity.runtime.log.ServletLogChute,org.apache.velocity.runtime.log.JdkLogChute
Upvotes: 1