almost 4 years ago

整合spring跟log4j很方便

修改web.xml

web.xml
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/conf/log4j.properties</param-value>
</context-param>
<context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>3600000</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

新增/WEB-INF/conf/log4j.properties檔案

在發佈以後可以將WebAP路徑改以${webapp.root}取代
ex:log4j.appender.all.File=${webapp.root}/WEB-INF/syslog/system.log,
但是如果是開發環境上這樣設定,log會寫到D:\workspace\Payment.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\apname\WEB-INF\syslog 裡面去不好找

log4j.properties
# for all log
log4j.rootLogger = DEBUG,root,console

log4j.logger.all = DEBUG,all,console

log4j.logger.even = DEBUG,even,console

log4j.logger.input = DEBUG,input,console

log4j.logger.output = DEBUG,output,console


log4j.additivity.rootLogger=false

log4j.additivity.all=false

log4j.additivity.even=false

log4j.additivity.input=false

log4j.additivity.output=false


log4j.appender.console = org.apache.log4j.ConsoleAppender

log4j.appender.console.layout = org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n


log4j.appender.root=org.apache.log4j.DailyRollingFileAppender

log4j.appender.root.File=../webapps/apname/WEB-INF/syslog/system_root.log

log4j.appender.root.DatePattern='_'yyyy-MM-dd'.log'

log4j.appender.root.layout = org.apache.log4j.PatternLayout

log4j.appender.root.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] - %m%n


log4j.appender.all=org.apache.log4j.DailyRollingFileAppender

log4j.appender.all.File=../webapps/apname/WEB-INF/syslog/system.log

log4j.appender.all.DatePattern='_'yyyy-MM-dd'.log'

log4j.appender.all.layout = org.apache.log4j.PatternLayout

log4j.appender.all.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%l]-[%p] - %m%n


log4j.appender.even=org.apache.log4j.DailyRollingFileAppender

log4j.appender.even.File=../webapps/apname/WEB-INF/syslog/system_even.log

log4j.appender.even.DatePattern='_'yyyy-MM-dd'.log'

log4j.appender.even.layout = org.apache.log4j.PatternLayout

log4j.appender.even.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%l]-[%p] - %m%n


log4j.appender.input=org.apache.log4j.DailyRollingFileAppender

log4j.appender.input.File=../webapps/apname/WEB-INF/syslog/system_input.log

log4j.appender.input.DatePattern='_'yyyy-MM-dd'.log'

log4j.appender.input.layout = org.apache.log4j.PatternLayout

log4j.appender.input.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%l]-[%p] - %m%n


log4j.appender.output=org.apache.log4j.DailyRollingFileAppender

log4j.appender.output.File=../webapps/apname/WEB-INF/syslog/system_output.log

log4j.appender.output.DatePattern='_'yyyy-MM-dd'.log'

log4j.appender.output.layout = org.apache.log4j.PatternLayout

log4j.appender.output.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%l]-[%p] - %m%n
← GitServer安裝 WebserviceClient →
 
comments powered by Disqus