posts - 10, comments - 9, trackbacks - 0, articles - 17

velocity配置log4j过程及注意.

Posted on 2010-07-28 11:39 wesley1987 阅读(2462) 评论(0)  编辑  收藏
1。指定velocity.properties文件,  默认路径为 WEB-INF/velocity.properties 也可自定义路径, 在web.xml中
      <servlet>
        
<servlet-name>velocity</servlet-name>
        
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityLayoutServlet</servlet-class>
        
<init-param>
            
<param-name>org.apache.velocity.properties</param-name>
            
<param-value>/WEB-INF/config/velocity.properties</param-value>
        
</init-param>
        
<init-param>
            
<param-name>org.apache.velocity.toolbox</param-name>
            
<param-value>/WEB-INF/config/velocity-toolbox.xml</param-value>
        
</init-param>
        
<load-on-startup>5</load-on-startup>
      
</servlet>
注意 load-on-startup 需要配置且靠后, 否则启动时看不到日志.

2。在velocity.properties中配置日程相关参数:
#----------------------------------------------------------------------------
#  default LogSystem to use: default: AvalonLogSystem
#----------------------------------------------------------------------------


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

runtime
.log.logsystem.log4j.category = velocity_log

#----------------------------------------------------------------------------
# This controls if Runtime.error(), info() and warn() messages include the
# whole stack trace. The last property controls whether invalid references
# are logged.
#----------------------------------------------------------------------------


runtime
.log.error.stacktrace = false
runtime
.log.warn.stacktrace = false
runtime
.log.info.stacktrace = false
runtime
.log.invalid.reference = true


3\ 配置log4j.properties,  具体配置意义请参看log4j配置相关文档
log4j.rootLogger=INFO,CONSOLE,FILE
log4j
.logger.velocity_log=INFO,CONSOLE,VELOCITY
log4j
.addivity.org.apache=true

log4j
.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j
.appender.CONSOLE.Threshold=WARN
log4j
.appender.CONSOLE.Target=System.out
log4j
.appender.CONSOLE.Encoding=GBK
log4j
.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j
.appender.CONSOLE.layout.ConversionPattern=[%-4p] %d{MM-dd HH:mm} - %m  %n

log4j
.appender.VELOCITY=org.apache.log4j.FileAppender
log4j
.appender.VELOCITY.File=E:/workspace/dwrt/WebRoot/log/velocity.log
log4j
.appender.VELOCITY.Append=false
log4j
.appender.VELOCITY.Encoding=GBK
log4j
.appender.VELOCITY.layout=org.apache.log4j.PatternLayout
log4j
.appender.VELOCITY.layout.ConversionPattern=[%-4p] %d{MM-dd HH:mm} - %m  %n

只有注册用户登录后才能发表评论。


网站导航: