簡體   English   中英

如何禁用速度日志

[英]How to disable velocity logs

我一直在嘗試禁用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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM