2013-10-18 8 views
12

私はベロシティのログを無効にしようとしてきた、と私は肯定的な結果とこれまでのところ見つけた唯一の方法で設定することです:速度ログを無効にする方法

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

をしかしvelocity.properties内でそれが常駐velocity.jarの内部にあります。

私はWebアプリケーション(tomcat)コンテキストで速度を使用しています。 JARを変更せずに速度を無効にする方法はありますか(前のプロパティを設定するなど)

これはあなたがvelocityで所望のロギングを設定する方法である任意のコードに事前

+0

後、アプリケーションログのプロパティを呼び出された場合
ルック、 – Keerthivasan

+0

私はちょうどそれの内部速度に関して何もlog4j.propertiesを持っ – luiso1979

答えて

2

感謝を変更できません:

//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レベルから何も具体的には出ません。

+0

私がいることを忘れてしまった場合は申し訳ありません、コードを(触れることができません詳細、私は質問を編集します) – luiso1979

+0

また、私はVelocity [documentation](http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Logging) – luiso1979

2

あなたはVelocityBuilderインタフェースのメソッドVelocityEngineエンジンを()を実装して、あなたは次のように使用するファイルを指定することができます:あなたのvelocity.propertiesファイルで

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; 
      } 

そして後に:

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 
12

一般に:ちょうどあなたの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)が...どこかのコードで