开发者

Why is there no output in the website.log file. Is there something wrong with log4j.properties

开发者 https://www.devze.com 2023-02-19 22:51 出处:网络
The contents of log4.properties are: log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=D:\\\\tomcat\\\\logs\\\\website.log

The contents of log4.properties are:

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=D:\\tomcat\\logs\\website.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.R.MaxFileSize=200KB
log4j.appender.R.MaxBackupIndex=1
log4j.rootLogger=WARN, R 
log4j.logger.website=DEBUG

--

//The java class that outputs to  website.log by invoking
//logger.debug("HomeServlet.doGet()"); 

package home;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

public class HomeServlet extends HttpServlet {


private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(this.getClass());


    /**
    * @see HttpServlet#HttpServlet()
    */
  开发者_C百科  public HomeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

     /**
     * @see HttpServlet#doGet(HttpServletRequest request, 
     *                    HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException 
    {
        PrintWriter out = response.getWriter();
        System.out.println("<html><body>Debug!</body></html>");
        logger.debug("HomeServlet.doGet()");
    }

     /**
     * @see HttpServlet#doPost(HttpServletRequest request, 
     *                     HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException 
    {
        // TODO Auto-generated method stub
    }
}


You need:

log4j.category.HomeServlet = DEBUG, R

In your log4j.properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消