Java 如何禁用速度日志
我一直在尝试禁用Velocity日志,到目前为止,我找到的唯一一种方法是设置:Java 如何禁用速度日志,java,tomcat,logging,velocity,Java,Tomcat,Logging,Velocity,我一直在尝试禁用Velocity日志,到目前为止,我找到的唯一一种方法是设置: runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogSystem 但是在velocity.jar中的velocity.properties中 我在Web应用程序(tomcat)上下文中使用velocity。有没有办法在不修改JAR的情况下禁用速度(通过设置previous属性或其他什么) 无法修改任何代码 提前感谢这是您如何配置所需登
runtime.log.logsystem.class=org.apache.velocity.runtime.log.NullLogSystem
但是在velocity.jar中的velocity.properties中
我在Web应用程序(tomcat)上下文中使用velocity。有没有办法在不修改JAR的情况下禁用速度(通过设置previous属性或其他什么)
无法修改任何代码
提前感谢这是您如何配置所需登录速度的方法:
//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
INFO
与velocity
配合良好,因为在启动时,您会注意到一些有用的velocity引擎配置详细信息,但在模板化过程中,INFO
级别没有任何特定信息。您可以实现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
一般来说:只需将以下行添加到您的
velocity.properties
:
runtime.log.logsystem.class=org.apache.velocity.runtime.log.nulllogs
关于你的问题:
这取决于速度引擎的加载方式。可以给它一个自定义的
velocity.properties
文件吗例如,Solr的
VelocityResponseWriter
具有名为v.properties
(或当前版本中的init.properties.file
)的属性看,如果方法
org.apache.velocity.app.VelocityEngine.init(Properties)
在代码中的某个地方被调用…发布应用程序日志属性我只有一个log4j.Properties,里面没有任何关于速度的内容。我也不能触摸代码(很抱歉,如果我忘记了这个细节,我会编辑这个问题),我从命令行读到了Velocity,你知道怎么做吗,比如使用系统属性?像java-Druntime.log.logsystem.class…
这样的操作似乎不起作用。我不是100%确定,但我认为velocity本身并没有读取系统属性来更新其配置@santon也许你可以解释一下你的答案,这会使它更有价值。
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName());
velocityEngine.init();