spring log4j.properties 沒有日誌的問題

一.   log4j.propertiesweb

1. log4j.properties放在spring工程的src/main/rescours目錄下沒法讀取。spring

   測試後發現須要把log4j.properties文件放在src/main/webapp/WEB-INF目錄下,app

2. web.xml配置webapp

<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>spa

3. log4j.properties中日誌文件路徑日誌

${webapp.root}/....  xml

4. 代碼get

private static final Log log= LogFactory.getLog("logname");io

 

二. log4j.xml

1. log4j.xml放在spring工程的src/main/rescours目錄下能夠讀取。

2. web.xml配置

<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. log4j.properties中日誌文件路徑

${webapp.root}/....  

4. 代碼

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

private static final Logger log= LoggerFactory.getLogger("logname");

相關文章
相關標籤/搜索