<span><span># defines the DEBUG priority, R is </span></span>log4j.rootlogger=debug,appender1 for log output purposes
, Appender2
<pre name= "code" class= "HTML" ><span># Setup log output console
</span>
Log4j.appender.appender1=org.apache.log4j.consoleappender
<span><span># log Output Information format type </span></span>
Log4j.appender.appender1.layout=org.apache.log4j.patternlayout
<span># Log output information is formatted as date, </span><span> priority, full class path, </span> log information, newline <span></span>< Span></span>
LOG4J.APPENDER.APPENDER1.LAYOUT.CONVERSIONPATTERN=[%D{YY/MM/DD Hh:mm:ss:sss}]%p[%c]%m%n
# set log output type, Log4j.appender.appender2=org.apache.log4j.dailyrollingfileappender for file type
# Log Output Information format type Log4j.appender.appender2.layout=org.apache.log4j.patternlayout
# Log output information is formatted as date, log information, newline
Log4j.appender.appender2.layout.conversionpattern=[%d{yy--mm--hh HH:mm:ss}]%m%n
<span># log output file name and address </span>
Log4j.appender.appender2.file=d:/log/log.log
# BACKUP Log
Log4j.appender.appender2.DatePattern = '. ' Yyyy-mm-dd
The Web.xml is set as follows
<servlet>
<servlet-name>Log4jInit</servlet-name>
<servlet-class> full class path </ servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value >/WEB-INF/classes/log4j.properties</param-value>
</init-param>
</servlet>
Implementation class
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Org.apache.log4j.PropertyConfigurator;
public class Log4jinit extends HttpServlet {
private static final long serialversionuid = 1L;
public void Destroy () {
Super.destroy ();
}
Public Log4jinit () {
super ();
}
public void Init () throws servletexception {
String file =this.getinitparameter ("log4j"); Read from the Web.xml configuration, the name must be configured with the Web.xml consistent
if (file!= null) {
propertyconfigurator.configure (file);}
}}