Spring Integration:
config log4j in Web. XML
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/log4j.xml</param-value>
</context-param>
<!--load the log4j listener in the spring frame Log4jconfiglistener-
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
=============================================================================================================== ===
log4j Basic ConceptsLogger: Log output, provides output log function. Appender: The log destination used to define the log destination object. Several common Appender, the first two are more commonly used: Consoleappender: Console as the log output to Dailyrollingfileappender:generate a log file
every day Fileappender: The file is rollingfileappender as the log output: the size of the log file is limited, and when the content exceeds the maximum limit, the file scrolls uppatternlayout: Log layout for defining the log formatlog4j.xml Actual configuration<!--the console's log records--<appender name= "console" class= "Org.apache.log4j.ConsoleAppender" ><param name= "encoding" value= "UTF-8"/><param name= "target" value= "System.out"/><layout class= "Org.apache.log4j.PatternLayout" ><param name= "Conversionpattern" value= "%d%-5p%c{2} (%l)-%m%n"/></layout></appender><!--default -- <!--output to log file one log per day--
<appender name= "Default-appender" class= "Org.apache.log4j.DailyRollingFileAppender" > <!--set the file parameter: Log output file name--
<param name= "file" value= "/neworiental/web/log/common-default.log"/> <!--set whether to add a new log on the base of the original log when the service is restarted--
<param name= "append" value= "true"/><!--encoded format -<param name= "encoding" value= "UTF-8"/> <!--set the output file item and format--
<layout class= "Org.apache.log4j.PatternLayout" ><param name= "Conversionpattern" value= "%d%-5p%c{2}-%m%n"/></layout></appender><!--error log --<!--output to log file one log per day--
<appender name= "Error-appender" class= "Org.apache.log4j.DailyRollingFileAppender" ><param name= "file" value= "/neworiental/web/log/common-error.log"/><param name= "append" value= "true"/><param name= "encoding" value= "UTF-8"/><!--log levels --<param name= "threshold" value= "error"/><layout class= "Org.apache.log4j.PatternLayout" ><param name= "Conversionpattern" value= "%d%-5p%c{2} (%l)-%m%n"/></layout></appender><!--[public logger] Console stdout-stdout --<logger name= "STDOUT" additivity= "false" ><level value= "INFO"/><appender-ref ref= "Console"/><appender-ref ref= "Goodhope-info"/></logger><!--application path [Logger] By default --<logger name= "path: which file to output the log under" additivity= "false" ><appender-ref ref= "Console"/><appender-ref ref= "Default-appender"/><appender-ref ref= "Error-appender"/></logger><root><level value= "info"/><appender-ref ref= "Console"/><appender-ref ref= "Default-appender"/><appender-ref ref= "Error-appender"/></root>
Spring integrated log4j and log4j configuration brief description