log4j的问题?

kln78 2005-03-24 10:46:04
在web开发中使用,把log4j.properties放在projectman\web-inf\下,写了Log4JServlet放在serv包下,并在web.xml中写好servlet的配置,在JSP中应用。
启动tomcat,浏览网页后,在控制台出现以下提示
log4j:WARN No appenders could be found for logger (projectmanLogger).
log4j:WARN Please initialize the log4j system properly.

log4j.properties如下:log4j.rootLogger=INFO,console,file
#define a logger named projectmanLogger
log4j.logger.projectmanLogger=WARN,console,file,debug

##APPENDERS##
#define an appender named console,which is set to be a ConsoleAppender
log4j.appender.console=org.apache.log4j.ConsoleAppender

#define an appender named file,which is set to be a RollingFileAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:/eclipse/workspace/project/projectman/WEB-INF/log.txt

##LAYOUTS##
#assign a SimpleLayout to console appender
log4j.appender.console.layout=org.apache.log4j.SimpleLayout

#assign a PatternLayout to file appender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%t%p-%m%m


log4jservlet如下:
/*
* 创建日期 2005-5-23
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package serv;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.*;


/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class Log4JServlet extends HttpServlet {

public void init(ServletConfig config) throws ServletException {
super.init(config);
//TODO Method stub generated by Lomboz
}

public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
//TODO Method stub generated by Lomboz
String path=getServletContext().getRealPath("/");
String profile=path+getInitParameter("profile");

PropertyConfigurator.configure(profile);
}
}

web.xml如下
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>serv.LoginServlet</servlet-class>
<init-param>
<param-name>propfile</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

login.jsp如下:
<%@page import="org.apache.log4j.Logger"%>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>projectman</title>
</head>
<body bgcolor="#FFFFFF">

<%
Logger projectmanLogger=Logger.getLogger("projectmanLogger");
projectmanLogger.debug("this is a log message from the"+projectmanLogger.getName());
projectmanLogger.info("this is a log message from the"+projectmanLogger.getName());
projectmanLogger.warn("this is a log message from the"+projectmanLogger.getName());
projectmanLogger.error("this is a log message from the"+projectmanLogger.getName());
projectmanLogger.fatal("this is a log message from the"+projectmanLogger.getName());
%>
<form name="loginForm" method="post" action="index.jsp">
<table>
<tr><td>USER NAME<input type="text" name="username"></td></tr>
<tr><td>PASSWORD<input type="password" name="password"</td></tr>
<tr><td><input type="Submit" name="Submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>
...全文
104 点赞 收藏 4
写回复
4 条回复
feifeirao 2005年07月04日
up 我 也 遇到 同样的问题
回复 点赞
kln78 2005年03月28日
已经把log4j-1.2.9.jar放在了WEB-INF/lib里了.
回复 点赞
myth822 2005年03月24日
log4j.jar的包引了吗?
回复 点赞
kln78 2005年03月24日
自己顶
回复 点赞
发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告