Spring boot logback can not logging to file on kubernetes multiple pods

7/8/2020

similar when start application the multi pods on k8s (2 pods) It's can write logging file to that's pods, So when next day i'm try request to service for logging console can show normally but on logging file i'm found only one pod can write logging to file but another pods can not write logging to file.

Please help me to solve this point

This is my logback.xml file

<?xml version="1.0" encoding="UTF-8"?><configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<property name="CONSOLE_LOG_PATTERN"
          value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<property name="FILE_LOG_PATTERN"
          value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>

<property name="LOG_LOCATION" value="logs" />
<property name="LOG_ARCHIVED_FOLDER" value="archived" />
<property name="LOG_FILE" value="my-log-app" />
<property name="maxFileSize" value="100MB" />
<property name="totalSizeCap" value="60GB" />
<property name="maxHistory" value="120" />

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
    <resetJUL>true</resetJUL>
</contextListener>

<!-- To enable JMX Management -->
<jmxConfigurator/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <charset>UTF-8</charset>
        <pattern>${CONSOLE_LOG_PATTERN}</pattern>
    </encoder>
</appender>

<appender name="FILE_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_LOCATION}/${LOG_FILE}.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <fileNamePattern>${LOG_LOCATION}/${LOG_ARCHIVED_FOLDER}/${LOG_FILE}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <!-- each archived file, size max 100MB -->
        <maxFileSize>${maxFileSize}</maxFileSize>
        <!-- total size of all archive files, if total size > 60GB, it will delete old archived file -->
        <totalSizeCap>${totalSizeCap}</totalSizeCap>
        <!-- 120 days to keep -->
        <maxHistory>${maxHistory}</maxHistory>
    </rollingPolicy>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <charset>UTF-8</charset>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
</appender>

<appender name="ASYNC_CONSOLE" class="ch.qos.logback.classic.AsyncAppender">
    <discardingThreshold>0</discardingThreshold> <!-- default 20, means drop lower event when has 20% capacity remaining -->
    <appender-ref ref="CONSOLE" />
    <queueSize>1</queueSize> <!-- default 256 -->
    <includeCallerData>false</includeCallerData><!-- default false -->
    <neverBlock>true</neverBlock><!-- default false, set to true to cause the Appender not block the application and just drop the messages -->
</appender>

<appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
    <discardingThreshold>0</discardingThreshold> <!-- default 20, means drop lower event when has 20% capacity remaining -->
    <appender-ref ref="FILE_ROLLING" />
    <queueSize>1</queueSize> <!-- default 256 -->
    <includeCallerData>false</includeCallerData><!-- default false -->
    <neverBlock>false</neverBlock><!-- default false, set to true to cause the Appender not block the application and just drop the messages -->
</appender>

<springProfile name="dev">
    <root level="INFO">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </root>
    <root level="ERROR">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </root>
    <logger name="com.example" level="TRACE" additivity="false">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </logger>
</springProfile>

<springProfile name="prod">
    <root level="INFO">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </root>
    <root level="ERROR">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </root>
    <logger name="com.example" level="TRACE" additivity="false">
        <appender-ref ref="ASYNC_CONSOLE" />
        <appender-ref ref="ASYNC_FILE"/>
    </logger>
</springProfile>
</configuration>
-- K&#39;Phai
kubernetes
logback
microservices
spring-boot

0 Answers