Spring MVC log4j Configuration

Source: Internet
Author: User

1, the first page in the Web-inf directory under the new log4j.properties configuration file, the contents are as follows:

 log4j.rootcategory = Info,dailyfile log4j.appender.dailyFile  =org.apache.log4j.dailyrollingfileappenderlog4j.appender.dailyfile.threshold  = DEBUG log4j.appender.dailyFile.ImmediateFlush  =true  log4j.appender.dailyfile.append  =true  log4j.appender.dailyfile.file  =c:/logs/ Log.loglog4j.appender.dailyFile.DatePattern  =yyyy-mm-dd .log   "  = Org.apache.log4j.PatternLayoutlog4j.appender.dailyFile.layout.ConversionPattern  =[%-5p]%d (%r)--[%t]% L:%m%x%n 

2. Modify the Web. XML configuration to add the following configuration to the first-level node:

<context-param>   <param-name>log4jConfigLocation</param-name>   <param-value>/ Web-inf/log4j.properties</param-value></context-param><listener>   <listener-class >    org.springframework.web.util.Log4jConfigListener   </listener-class> </listener>

3. Use in Java files:

Logger log = Logger.getlogger (this. GetClass (). GetName ()); Log.info ("  Logger  ");  Log.error ("error"); // log.debug ("Debug");

Debug is not written to the log here. See Log4j.properties for detailed configuration instructions.

Spring MVC log4j Configuration

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.