2012-03-14 115 views
5

logback.xml的logback SLF4J無法獲得日誌報表日誌文件中

<?xml version="1.0" encoding="UTF-8"?> 

                --> 
<configuration> 
<!-- Errors were reported during translation. --> 
<!-- No root logger configuration was found --> 

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <layout class="ch.qos.logback.classic.PatternLayout"> 
     <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 
     </Pattern> 
    </layout> 
</appender> 


<appender name="FILE" class="ch.qos.logback.core.FileAppender"> 
<file>c:\log\test.log</file> 
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
<pattern>%msg%n</pattern> 
</encoder> 
</appender> 

<logger name="com.base22" level="DEBUG" /> 
<root level="debug"> 
    <appender-ref ref="STDOUT" /> 
    <appender-ref ref="FILE" /> 
</root> 
</configuration> 

的pom.xml依賴

<dependency> 
<groupId>org.slf4j</groupId> 
<artifactId>slf4j-api</artifactId> 
<version>1.6.1</version> 
</dependency> 


<dependency> 
<groupId>org.slf4j</groupId> 
<artifactId>jcl-over-slf4j</artifactId> 
<version>1.6.1</version> 
</dependency> 

<dependency> 
<groupId>ch.qos.logback</groupId> 
<artifactId>logback-classic</artifactId> 
<version>0.9.26</version> 
</dependency> 

    <dependency> 
<groupId>ch.qos.logback</groupId> 
<artifactId>logback-core</artifactId> 
<version>0.9.26</version> 
</dependency> 

<dependency> 
<groupId>ch.qos.logback</groupId> 
<artifactId>logback-access</artifactId> 
<version>0.9.26</version> 
</dependency> 

採用上述配置的logback爲日誌.....報表上顯示控制檯但test.log沒有創建,我沒有找到任何日誌,即使在我創建文件之後的文件..我需要編寫任何其他配置

回答

3

您的logback.xml不放在哪裏logback尋找它,小號它靜靜地回落到「打印到控制檯」配置。關於配置機制的所有細節,請參閱http://logback.qos.ch/manual/configuration.html

+0

我很感謝我把這個文件放在WEB-INF下,因爲它不工作 – user1265530 2012-03-15 15:44:20