Содержимое log4.properties:
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()
*/
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
}
}