jeudi 25 juin 2015

Where does the ServletContext.log messages go in tomcat 7?

I am using Java 7, tomcat 7. While learning about servlet logging I wrote a simple program.

package net.codejava;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LogCheck
 */
@WebServlet("/LogCheck")
public class LogCheck extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public LogCheck() {
    super();
    // TODO Auto-generated constructor stub
}

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

    ServletContext context = getServletContext();
    String par = request.getParameter("msg");

    if (par == null || par.equals("")){
        context.log("No Message received",new IllegalStateException("Missing Parameter"));
    }else{
        context.log("Here is visitor's message:"+par);
    }

    PrintWriter out = response.getWriter();
    out.println("Log Testing.");

}

}

Now I am able to see the log messages in my Eclipse console. But I do not see any files under Tomcat Home/logs folder ? But I read that it should store the log messages in some log files. I do not see any log file in my case.

Am I missing some configuraions? Please help

Aucun commentaire:

Enregistrer un commentaire