在我的web項目中,我嘗試使用帶有logback的SLF4j,當我在本地機器上的Tomacat上啓動應用程序時,我粘貼了SLF4j xml設置以及POM部分。我沒有看到任何錯誤,也沒有生成日誌。用於記錄罐子Maven POM文件的SLF4j不寫入日誌文件
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyyddMM:HHmmss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./myapp.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>./myapp.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>14</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyyddMM:HHmmss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./myapp_debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>./myapp_debug.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>1</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyyddMM:HHmmss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- logger name="com.base22" level="TRACE"/ -->
<logger name="com.sample.app" level="TRACE" />
<logger name="org.apache" level="ERROR" />
<logger name="org.springframework" level="ERROR" />
<logger name="org.hibernate" level="ERROR" />
<logger name="java.sql" level="ERROR" />
<logger name="jdbc.audit" level="ERROR" />
<logger name="jdbc.connection" level="ERROR" />
<logger name="jdbc.sqltiming" level="ERROR" />
<logger name="jdbc.resultset" level="ERROR" />
<logger name="jdbc.resultsettable" level="ERROR" />
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="DEBUG" />
</root>
</configuration>
科
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
裏面一個Web容器使用Java util記錄作爲後端,所以容器將收集它。 –