如何禁用速度日志

时间:2013-10-18 06:52:06

标签: java tomcat logging velocity

我一直在尝试禁用Velocity日志,到目前为止我发现的唯一方法就是设置:

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

但位于velocity.jar内的velocity.properties内。

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

无法修改任何代码

提前致谢

4 个答案:

答案 0 :(得分:13)

一般:只需将以下行添加到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) ......

答案 1 :(得分:5)

这是您在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

恕我直言INFOvelocity一样好,因为在启动时你会注意到一些有用的速度引擎配置细节,但在模板化过程中没有任何具体的内容来自INFO级别。

答案 2 :(得分:3)

您可以实现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

答案 3 :(得分:0)

VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName());
velocityEngine.init();
相关问题