在 spring boot 项目中,logback 配置如下..现在的问题是,如果有任何异常,它不存在于日志文件中,但它显示在 stdout 中。
<configuration debug="true" scan="true" scanPeriod="30 seconds">
<timestamp key="bySecond" datePattern="yyyy-MM-dd:HH-mm-ss.SSS"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<append>true</append>
<file>/var/log/app/backend-business-workflow/${MY_POD_NAMESPACE}_${HOSTNAME}_application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/var/log/app/backend-business-workflow/archive/${MY_POD_NAMESPACE}_${HOSTNAME}_application.log.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<!-- <pattern>"timestamp":"%date","requestId":"%X{x_request_id}","spanId":"%X{x_span_id}","level":"%level","threadId":"[%thread]","class":"[%file:%line]","message":"%msg"%n</pattern>-->
<timestampPattern>yyyy-MM-dd HH:mm:ss.SSS</timestampPattern>
<includeCallerData>true</includeCallerData>
<includeMdcKeyName>x_request_id</includeMdcKeyName>
<includeMdcKeyName>x_span_id</includeMdcKeyName>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %X{x_request_id} %X{x_span_id} %level [%thread] [%file:%line] %msg%n</pattern>
<outputPatternAsHeader>true</outputPatternAsHeader>
</encoder>
</appender>
<!-- <logger >-->
<!--<!– <level value="INFO" />–>-->
<!-- <appender-ref ref="STDOUT" />-->
<!-- <appender-ref ref="FILE" />-->
<!-- </logger>-->
<root >
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>