为什么logger.info只输出6行?

时间:2018-05-16 01:55:21

标签: spring-boot logback slf4j

我的项目基于spring-boot框架。以下是logback-spring.xml中的配置

    <appender name="defaultLogFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${system.log.path}/${appName}-default.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${system.log.path}/${appName}-default.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>10MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <maxHistory>10</maxHistory>
    </rollingPolicy>
    <append>true</append>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <pattern>%date [%thread] %-5level %logger{36} Method:%M Line:%L - %msg%n</pattern>
        <charset>UTF-8</charset>
    </encoder>
</appender>

以下是记录器代码:

    for (int i = 0; i < 100; i++){
        logger.info("asdfasdfsadf i = {}", i);

        try {
            TimeUnit.SECONDS.sleep(2);
        }
        catch (Exception e) {
            System.out.println("dddddd");
        }
    }

以下是记录器信息的输出。

2018-05-16 09:18:16,164 [main] INFO  c.x.********.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 0
2018-05-16 09:18:16.164  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 0
2018-05-16 09:18:18,169 [main] INFO  c.x.*******.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 1
2018-05-16 09:18:18.169  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 1
2018-05-16 09:18:20,172 [main] INFO  c.x.*******.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 2
2018-05-16 09:18:20.172  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 2
2018-05-16 09:18:22,176 [main] INFO  c.x.*******.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 3
2018-05-16 09:18:22.176  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 3
2018-05-16 09:18:24,181 [main] INFO  c.x.*******.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 4
2018-05-16 09:18:24.181  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 4
2018-05-16 09:18:26,184 [main] INFO  c.x.*******.RecommendationTest 
Method:test Line:58 - asdfasdfsadf i = 5
2018-05-16 09:18:26.184  INFO 1399 --- [           main] 
com.*******.RecommendationTest  : asdfasdfsadf i = 5

只有6行,为什么?欢迎任何建议或建议。

1 个答案:

答案 0 :(得分:1)

你可以粘贴你在application.properties中编写的代码来包含这个logback.xml吗? 查看您的logback文件,您似乎正在生成日常备份文件。 可能有异常的机会所以请在catch中添加logger.info而不是SOP,希望它能给出一些提示。 请尝试运行代码从logback.xml中删除代码