Problem when using Logger with Tomcat and eclipse
Hi,
Iam using Tomcat 5.5.7 and my IDE is eclipse.Iam using java.util.logging.Logger class for logging.Iam putting the properties file
in Appname/WEB-INF directory.The properties file is not identified.The error Iam getting is
Error initialising log file java.lang.NullPointerException and java.io.FileNot FoundException
The content of my logging.properties file is
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=SEVERE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.pattern=%h/javalogs%u.log
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.count=1
and my servlet is
import java.io.*;
import java.util.logging.*;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
try
{
String file=getServletConfig().getInitParameter("java.util.logging.config.file");
InputStream is = getServletContext().getResourceAsStream(file);
LogManager.getLogManager().reset();
LogManager.getLogManager().readConfiguration(is);
}
catch(Exception e)
{
System.out.println("Error initialising log file"+e);
}
}
public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
final Logger fLogger =
Logger.getLogger(HelloWorldServlet.class.getName());
PrintWriter out;
String title = "Simple Servlet Output";
// set content type and other response header fields first
// then write the data of the response
response.setContentType("text/html");
fLogger.finest("this is finest");
fLogger.finer("this is finer");
fLogger.fine("this is fine");
fLogger.config("this is config");
fLogger.info("this is info");
fLogger.warning("this is a warning");
fLogger.severe("this is severe");
out = response.getWriter();
out.println("<P>This is output from SimpleServlet!!!!!!!!.");
}
}
My web.xml file is
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<init-param>
<param-name>java.util.logging.config.file</param-name>
<param-value>/WEB-INF/classes/logging1.properties</param-value>
</init-param>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
Can anybody help me out.