Spring integrated log4j and log4j configuration brief description

Source: Internet
Author: User

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

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.