如何禁用速度日志

我一直试图禁用Velocity日志,到目前为止我发现的唯一方法是积极的结果是设置:

runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogSystem 

但是在velocity.jar里面的velocity.properties里面。

我在Web应用程序(tomcat)上下文中使用velocity。 有没有办法禁用速度(通过设置以前的属性或其他)但不修改JAR?

无法修改任何CODE

提前致谢

通常 :只需在velocity.properties添加以下行:

 runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogChute 

问题 :这取决于速度引擎的加载方式。 是否可以为其提供自定义的velocity.properties文件?
例如,Solr的VelocityResponseWriter具有名为v.properties (或当前版本的init.properties.file )的属性。
看,如果在代码中某处调用org.apache.velocity.app.VelocityEngine.init(Properties)方法…

这是您如何配置所需的velocity记录:

 //java configuration VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute" ); ve.setProperty("runtime.log.logsystem.log4j.logger","velocity"); //log4j properties log4j.category.velocity=WARN 

IMHO INFOvelocity方面很好,在启动时您会注意到一些有用的速度引擎配置细节,但在模板化过程中没有任何具体的INFO来自INFO级别。

您可以实现VelocityBuilder接口的VelocityEngine engine()方法,然后指定要使用的文件,如下所示:

  public VelocityEngine engine() { if(engine == null) { engine = new VelocityEngine(); Properties properties = new Properties(); InputStream in = null; try { //here is where you specify the filename "/WEB-INF/velocity.properties" in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties"); properties.load(in); engine.init(properties); } catch (IOException e) { e.printStackTrace(); logger.error("Error loading velocity engine properties"); throw new ProgramException("Cannot load velocity engine properties"); } IOUtils.closeQuietly(in); } return engine; } 

在你的velocity.properties文件之后:

 resource.loader = framework framework.resource.loader.description = Framework Templates Resource Loader framework.resource.loader.class = applica.framework.library.velocity.WEBINFResourceLoader webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader webapp.resource.loader.path = runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogSystem file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.path = class.resource.loader.description = Velocity Classpath Resource Loader class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 
 VelocityEngine velocityEngine = new VelocityEngine(); velocityEngine.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName()); velocityEngine.init();