jbossでwarファイルを使用してデプロイするspring-mvc/mavenアプリケーションを開発中です。私はlog4jを使ってデータベースにログを挿入しました。ここに私のlog4j.propertiesファイルのスニペットがあります。aplication.propertiesファイルからweb.xmlにlog4j.propertiesファイルのパスを取得する
log4j.rootLogger=ERROR, CONSOLE
log4j.logger.com.ge.epay.web.controller=INFO
log4j.logger.com.ge=ERROR
log4j.logger.org.springframework=ERROR
log4j.logger.org.acegisecurity=ERROR
log4j.logger.org.apache=ERROR
log4j.logger.java.sql=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.com.mchange=ERROR
私はlog4j.propertiesでの変更を行った後、アプリケーションを再配備することなく、DEBUGにERRORからログレベルを変更するようでした。
私はwar4j.propertiesファイルを戦争の外に保ち、web.xmlにLog4jConfigListenerを使用しました。以下は私のweb.xmlファイルのスニペットです。
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:/some path</param-value>
</context-param>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<!-- Time interval in millisecond after which the log4j properties will
be refreshed from the external file -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1200000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
私はlog4jConfigLocationパラメータとしての私のweb.xml自体にlog4j.properiesファイルのパスを定義しています見ることができるように。
この場所をapplication.propertiesファイルまたはenvironment.propertiesファイルで定義する必要があります。
プロパティファイルからロケーションを取得し、web.xmlで使用できますか?
log4j.propertiesファイルを戦争の外に置いてアプリケーションから読み取ることは安全ですか?
ありがとうございます。
log4j.propertiesファイルは、プロジェクト内ではないかもしれないクラスパスとしてあなたのプロパティファイルの場所を設定し、クラスパスから読み取るされる傾向にあります。それは他の場所に置かれます。そのパスはweb.xml – Waquar
はいに記載されていますので、その場所をクラスパスに追加してください –