One: The introduction of the log4j-dependent jar package, if not MAVEN project, directly to download the jar package, put it in the project's Lib directory.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
Second: In the engineering of the SRC directory to add File Log4j.properties, and add content
# # #设置 ###
Log4j.rootlogger = Debug, console, I, D, E, F
### output information to control lift ###
Log4j.appender.console = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.console.Target = System.out
Log4j.appender.console.layout = Org.apache.log4j.PatternLayout
Log4j.appender.console.layout.ConversionPattern = [%-5p]%d{yyyy-mm-dd hh\:mm\:ss,sss} console\:%m-%l%n
### output debug level above log to =e://logs/error.log ###
LOG4J.APPENDER.D = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.d.file = E\://logs/debug.log
Log4j.appender.d.append = True
Log4j.appender.d.threshold = DEBUG
Log4j.appender.d.layout = Org.apache.log4j.PatternLayout
Log4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd Hh\:mm\:ss} [%t\:%r]-[%p]%m-%l%n
### output the log above the error level to =e://logs/error.log ###
LOG4J.APPENDER.E = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.e.file =e\://logs/error.log
Log4j.appender.e.append = True
Log4j.appender.e.threshold = ERROR
Log4j.appender.e.layout = Org.apache.log4j.PatternLayout
Log4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd Hh\:mm\:ss} [%t\:%r]-[%p]%m-%l%n
### output info level above log to =e://logs/info.log ###
LOG4J.APPENDER.I = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.i.file =e\://logs/info.log
Log4j.appender.i.append = True
Log4j.appender.i.threshold = INFO
Log4j.appender.i.layout = Org.apache.log4j.PatternLayout
Log4j.appender.i.layout.conversionpattern =%-d{yyyy-mm-dd Hh\:mm\:ss} [%t\:%r]-[%p]%m-%l%n
### output fatal level above log to =e://logs/fatal.log ###
LOG4J.APPENDER.F = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.f.file =e\://logs/fatal.log
Log4j.appender.f.append = True
Log4j.appender.f.threshold = FATAL
Log4j.appender.f.layout = Org.apache.log4j.PatternLayout
Log4j.appender.f.layout.conversionpattern =%-d{yyyy-mm-dd Hh\:mm\:ss} [%t\:%r]-[%p]%m-%l%n
This defines five levels of logging, including the format for output to the console, and each type of log has a build policy, which is the configuration above
Three: Web.xml to join LOG4J configuration
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Four: Calling methods, generating objects inside a class
Private Logger Logger = Logger.getlogger (This.getclass (). GetName ());
Logger.error ("message");
Logger.info ("message");
This allows you to view the generated log on the E disk. This default configuration method general items are sufficient. Basically do not need any change, more strategy information, can Baidu understand. In fact, this configuration defines these types of logs, how they are generated, and what formats are generated.