LOG4 Basic Settings

Source: Internet
Author: User
Tags log4j
<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);}
	 }}

	




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.