您的位置:首页 > 其它

log4j使用详解

2008-10-15 11:24 316 查看
1.下载log4j.jar和commons-logging.jar文件.
2.将下载来的文件复制到myeclipse的web-inf/lib下
3.在/src目录下添加log4j.properties文件。编写文件内容如下:
#### Use two appenders, one to log to console, another to log to a file
log4j.rootCategory=DEGUG, stdout, R
# Print only messages of priority WARN or higher for your category
log4j.category.your.category.name=WARN
# Specifically inherit the priority level
#log4j.category.your.category.name=INHERITED
#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p-%d-%m%n
#### Second appender writes to a file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
# Control the maximum log file size
log4j.appender.R.MaxFileSize=100KB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p - %m%n
########################################################
4.然后修改web.xml,修改如下:添加实例化参数log4j
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</init-param>
启动服务器时候会讲/src/log4j.properties自动添加到/web-info/log4j.properties
5.但是服务器启动还是会出现:
log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester).
log4j:WARN Please initialize the log4j system properly.
恳请大家留言帮忙解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: