SpringBoot启动信息没有打印到日志文件中,怎么回事?

我的一个SpringCloud工程下一个SpringBoot程序,logback配置文件如下,在IDEA中,dev环境下启动的日志会打印在IDEA下的窗口中,但是配置了logback,要在测试机上prod环境运行,发现打印日志中部分启动日志没有打印,怎么回事?

`

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="10 seconds" debug="true">
        <property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS}  %-5level [%15.10thread] %class{30} - %msg %n"/>
        <property name="stdoutPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS}  %-5level [%15.10thread] %class{30} - %msg %n"/>

        <springProfile name="dev">
            <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
                <encoder charset="UTF-8">
                    <pattern>${stdoutPattern}</pattern>
                </encoder>
            </appender>
            <logger name="org.springframework"
                    level="ERROR">
            </logger>
            <logger name="java.sql">
                <level value="DEBUG"/>
            </logger>
            <logger name="org.mybatis">
                <level value="DEBUG"/>
            </logger>
            <logger name="org.apache.ibatis">
                <level value="DEBUG"/>
            </logger>
            <logger name="org.apache.zookeeper">
                <level value="INFO"/>
            </logger>
            <root level="INFO">
                <appender-ref ref="stdout" />
            </root>
                </springProfile>

        <springProfile name="prod">
            <property name="logPath" value="/app/logs" />
            <appender name="user" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>${logPath}/user.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${logPath}/user-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
                    <MaxHistory>10</MaxHistory>
                    <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                        <maxFileSize>500MB</maxFileSize>
                    </timeBasedFileNamingAndTriggeringPolicy>
                </rollingPolicy>
                <encoder charset="UTF-8">
                    <pattern>${pattern}</pattern>
                </encoder>
            </appender>

            <logger name="org.springframework"
                    level="ERROR">
            </logger>
            <logger name="java.sql">
                <level value="DEBUG"/>
            </logger>
            <logger name="org.mybatis">
                <level value="DEBUG"/>
            </logger>
            <logger name="org.apache.ibatis">
                <level value="DEBUG"/>
            </logger>
    <!--        <logger name="org.apache.zookeeper">
                        <level value="INFO"/>
            </logger>-->
            <root level="INFO">
                <appender-ref ref="user" />
            </root>
        </springProfile>
    </configuration>
            

`

没有在日志文件打印的日志主要是 ch.qos.logback.classic.joran.action.ConfigurationAction, ch.qos.logback.core.joran.action.AppenderAction,ch.qos.logback.classic.jul.LevelChangePropagator之类的,

譬如

Connected to the target VM, address: '127.0.0.1:59938', transport: 'socket'
23:32:23,686 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/Users/nan/mygit/pica/user/target/classes/logback-spring.xml] 
23:32:23,695 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 10 seconds
23:32:23,706 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
23:32:23,707 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]

日志文件打印的启动日志是从下面开始的

2020-03-24 15:29:08.044  INFO  [           main] o.s.boot.SpringApplication - The following profiles are active: prod
2020-03-24 15:29:09.560  DEBUG [           main] o.a.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
阅读 2k
评论
    1 个回答
    <springProfile name="prod">
                <property name="logPath" value="/app/logs" />
                <appender name="user" class="ch.qos.logback.core.rolling.RollingFileAppender">
                    <file>${logPath}/user.log</file>
                    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                        <fileNamePattern>${logPath}/user-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
                        <MaxHistory>10</MaxHistory>
                        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                            <maxFileSize>500MB</maxFileSize>
                        </timeBasedFileNamingAndTriggeringPolicy>
                    </rollingPolicy>
                    <encoder charset="UTF-8">
                        <pattern>${pattern}</pattern>
                    </encoder>
                </appender>
    
                <logger name="org.springframework"
                        level="ERROR">
                </logger>
                <logger name="java.sql">
                    <level value="DEBUG"/>
                </logger>
                <logger name="org.mybatis">
                    <level value="DEBUG"/>
                </logger>
                <logger name="org.apache.ibatis">
                    <level value="DEBUG"/>
                </logger>
        <!--        <logger name="org.apache.zookeeper">
                            <level value="INFO"/>
                </logger>-->
                <root level="INFO">
                    <appender-ref ref="user" />
                </root>
            </springProfile>

    注意看appender配置,ch.qos.logback.core.rolling.RollingFileAppender的意思是循环输出到文件。若想输出到控制台应该配置为ch.qos.logback.core.ConsoleAppender

      撰写回答

      登录后参与交流、获取后续更新提醒

      相似问题
      推荐文章