JavaScud | Forum | JIRA | Blog |
  Dashboard > SpringSide > Home > Log4j
  SpringSide Log In View a printable version of the current page.  
  Log4j
Added by calvin, last edited by calvin on Oct 11, 2006  (view change)
Labels: 
(None)

Log4j 使用要点

1. logfile 文件的路径定义

  logfile路径的规则是,如果不是绝对路径,就以应用运行的目录作为相对路径的根目录。

   Spring 提供了一种方式,将web应用的根目录设为环境变量,让你可以把路径设在web应用的WEB-INF目录

log4j.appender.logfile.File=${bookstore.root}/WEB-INF/logs/bookstore.log

   但这样做有个问题是war式的部署,每次重新部署的时候就会把原来的log文件全部删掉,遇上jboss 这种不解压war包的应用服务器就更会出错,所以把log文件放WEB-INF/logs不是一个好的选择。

  
   所以我一般这样定义,一般就指向tomcat 或很多应用服务器的logs目录:

   log4j.appender.logfile.File=../logs/bookstore.log

2. 忽略某些类库框架的不必要的信息

       控制这些类库框架的logging level,避免满屏都是不重要的info, 把真正重要的信息掩盖了。

# Control logging for other open source packages
# Changing the log level to DEBUG when debug
log4j.logger.org.springframework=WARN
# Changing the log level to DEBUG will display SQL Hibernate generated
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.SQL=ERROR

3. 把重要的业务log 异步批量写入数据库

    待写。

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators