logback.xml
<?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没有创建,我在创建文件后甚至在文件中找不到任何日志。我需要写任何其他配置
答案 0 :(得分:3)
您的logback.xml未放置在logback查找它的位置,因此它会静默地回退到“打印到控制台”配置。
有关配置机制的所有详细信息,请参阅http://logback.qos.ch/manual/configuration.html。