Spring Log4j.properties does not have a log problem

Source: Internet
Author: User

I. log4j.properties

1. Log4j.properties is not readable in the src/main/rescours directory of the spring project.

After the test found that the Log4j.properties file needs to be placed in the src/main/webapp/web-inf directory,

2. Web. XML configuration

<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. log file path in Log4j.properties

${webapp.root}/....

4. Code

private static final Log log= logfactorygetLog ("logname");

Two. Log4j.xml

1. Log4j.xml can be read in the src/main/rescours directory of the spring project.

2. Web. XML configuration

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>

<context-param>
<param-name>rootLevel</param-name>
<param-value>DEBUG</param-value>
</context-param>

<context-param>
<param-name>loggingLevel</param-name>
<param-value>INFO</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

3. log file path in Log4j.properties

${webapp.root}/....

4. Code

Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;

private static final Logger log= loggerfactorygetLogger ("logname");

Spring Log4j.properties does not have a log problem

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.