log4j在JSP项目中的应用


WEB-INF/classes下建立一个文件:log4j.properties,内容如下:

log4j.rootCategory=WARN, A1, R
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

# R is the RollingFileAppender that outputs to a rolling log
# file called rolling_log_file.log.

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log4j.log

# Define a pattern layout for the file. 
# For more information on conversion characters (i.e. d,p,t,c,l,m,n)
# please see the PatternLayout class of the Log4j API.

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[DATE]            %d{DATE}%n[PRIORITY]     %p%n[NDC]          %x%n[THREAD]       %t%n[CATEGORY]  %c%n[LOCATION]    %l%n[MESSAGE]    %m%n%n

# Set the max size of the file and the number of backup files

log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1

web.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "
http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

 <servlet>
  <servlet-name>log4j</servlet-name>
  <description>no description</description>
  <servlet-class>com.apache.jakarta.log4j.Log4jInit</servlet-class>
  <init-param>
  <param-name>log4j</param-name>
  <param-value>/WEB-INF/log4j.properties</param-value>
  </init-param>  
  
 </servlet>

</web-app>

 将log4j-1.2.8.jar放到WEB-INF/lib目录下。

即可使用

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值