Configure log4j for the Spring Framework in your project

Source: Internet
Author: User
Tags log4j
After you create a project based on the Spring Framework, the console prints a warning message when you use JUnit for unit testing:

Log4j:warn No Appenders could is found for logger (org.springframework.util.ClassUtils).
Log4j:warn Please initialize the log4j system properly.

Check on the Internet, incredibly many "suggestions" is to ignore these two warning messages, other search results are not satisfactory.
The workaround steps are as follows:
Name the log4j configuration file as log4j.properties. Add the Log4j.properties directory to the classpath. Add a Logger named Org.springframework to the log4j.properties. For example:
# Logger for Spring
Log4j.logger.org.springframework=debug, Org.springframework, stdout
Log4j.appender.org.springframework=org.apache.log4j.fileappender
Log4j.appender.org.springframework.file=/opt/adstat/log/spring.log
Log4j.appender.org.springframework.encoding=utf8
Log4j.appender.org.springframework.layout=org.apache.log4j.patternlayout
Log4j.appender.org.springframework.layout.conversionpattern=%-d{yyyy-mm-dd HH:MM:SS} [%c]-[%p]%m%n

After modification, the default settings required by Spring are met. Rerun the JUnit test, the above two warning messages are no longer displayed, and the corresponding Spring Framework information is exported to both the console and log files.

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.