The java.util.logging
API is still available, for those web applications that use it directly. The ${catalina.base}/conf/logging.properties
file is still referenced by Tomcat startup scripts.
Removal of ${catalina.base}/conf/logging.properties
file, mentioned as one of the steps, just causes java.util.logging
to fallback to the default configuration as configured in JRE, which is to use a ConsoleHandler and do not create any files.
package com.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.PropertyConfigurator;
@SuppressWarnings("serial")
public class Log4jServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public Log4jServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
System.setProperty("sembidhome", prefix);
if (file != null) {
PropertyConfigurator.configure(prefix + file);
}
}
}
<servlet>
<servlet-name>Log4jServlet</servlet-name>
<servlet-class>com.servlet.Log4jServlet</servlet-class>
<init-param>
<param-name>log4j-init-file</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Log4jServlet</servlet-name>
<url-pattern>/servlet/Log4jServlet</url-pattern>
</servlet-mapping>
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE,LOGFILE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.sss} [%-5p] %c (%M:%L) - %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=${sembidhome}/WEB-INF/logs/sembid.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.sss} [%-5p] %c (%M:%L) - %m%n
spring log4j:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
# Output pattern : date [thread] priority category - message
log4j.rootLogger=info,console,logFile
#Console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.sss} [%-5p] %c (%M:%L) - %m%n
#RollingFile
log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logFile.File=${webapp.root}/WEB-INF/logs/sem.log
log4j.appender.logFile.layout=org.apache.log4j.PatternLayout
log4j.appender.logFile.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.sss} [%-5p] %c (%M:%L) - %m%n