问答详情
源自:4-1 使用集成测试Service逻辑

为什么logback配置没有问题可是打印不出老师那样的一堆DEBUG信息呢?

表示从头到尾都跟老师打的一样呀,求大神解答呀!

https://img3.mukewang.com/5b5b183b0001f7f103610053.jpg

https://img4.mukewang.com/5b5b183b0001929715700729.jpg

https://img1.mukewang.com/5b5b183e000127c805360148.jpg


提问者:好学的滨滨 2018-07-27 21:05

个回答

  • 总悟君
    2018-08-13 12:18:22

    maven的porm.xml需要以下几个依赖

    <!-- sl4j -->

    <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    <version>1.7.10</version>

    </dependency>

    <dependency>

    <groupId>ch.qos.logback</groupId>

    <artifactId>logback-classic</artifactId>

    <version>1.1.2</version>

    </dependency>

    <dependency>

    <groupId>ch.qos.logback</groupId>

    <artifactId>logback-core</artifactId>

    <version>1.1.2</version>

    </dependency>


    logback.xml文件放到指定的文件夹目录下src/main/resources

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

    <configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

    <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder 

    by default -->

    <encoder>

    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>

    </encoder>

    </appender>


    <root level="debug">

    <appender-ref ref="STDOUT" />

    </root>

    </configuration>


    测试类当中像老师那样调用即可

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    logger.info("s={}", s);