我正在使用Apache Velocity 2.0。我正在尝试设置slf4j绑定。如Apache Velocity文档中所述,我设置了所需的依赖项。这样做并说我现在期望使用NOPLogger,因为没有任何日志使用。我的代码如下:
// Get template engine
VelocityEngine templateEngine = new VelocityEngine();
// Init template engine
templateEngine.addProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, new NOPLoggerFactory().getLogger(""));
templateEngine.init();
我的问题是执行“new VelocityEngine();”我在调试器控制台中跟踪跟踪:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://23.fwk288994035:3/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://23.fwk288994035:8/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
???
我已经看过Apache源代码了:
public class VelocityEngine implements RuntimeConstants
{
private RuntimeInstance ri = new RuntimeInstance();
....
}
public class RuntimeInstance implements RuntimeConstants, RuntimeServices
{
/**
* The Runtime logger. The default instance is the "org.apache.velocity" logger.
*/
private Logger log = LoggerFactory.getLogger(DEFAULT_RUNTIME_LOG_NAME);
....
}
听起来对我来说,记录器是先前的集成商获得指定它的能力......在我的环境中。我可能已经有一些其他记录器正在运行(我依赖的第三方贡献),所以我得到了如此无聊的痕迹。
我的分析可以吗?分享即将摆脱问题的任何技巧?
这是关于重复的slf4j罐子的警告,请参阅explanation:
如果类路径上有多个绑定,请选择一个且只能使用一个绑定,并删除其他绑定。例如,如果类路径上同时包含slf4j-simple-1.8.0-alpha2.jar和slf4j-nop-1.8.0-alpha2.jar,并且您希望使用nop(无操作)绑定,则删除来自类路径的slf4j-simple-1.8.0-alpha2.jar。
如果你需要在类路径中保持slf4j-simple,你根本就不能添加slf4j-nop jar。
在类路径中根本不可能有两个slf4j绑定jar。
您需要做的是通过configuring the SimpleLogger关闭Velocity日志。
例如,您可以定义以下系统属性:
org.slf4j.simpleLogger.log.org.apache.velocity = off