logginglogbacklogback-classic

Logback missing entries for RollingFileAppender and AysncAppender


Hi I am using logback version 1.1.10 and my configuration is as below: I am facing a big issue while logging events and not able to find the required logs.

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

<configuration>

  <appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>${log}/abc/request/request.log</File>
    <encoder>
      <pattern>%m%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
    </rollingPolicy>
  </appender>

  <appender name="abc1_res" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>${log}/abc1/response/response.log</File>
    <encoder>
      <pattern>%m%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${log}/abc1/response/response.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
    </rollingPolicy>
  </appender>

  <appender name="abc2_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>${log}/abc2/error/error.log</File>
    <encoder>
      <pattern>%m%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${log}/abc2/error/error.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
    </rollingPolicy>
  </appender>

  <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
    <Target>System.out</Target>
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p:: %m%n</pattern>
    </encoder>
  </appender>


  <logger name="abcLogRequest" level="INFO" additivity="false">
    <appender-ref ref="abc_req"/>
  </logger>
  <logger name="abc1LogResponse" level="INFO" additivity="false">
    <appender-ref ref="abc1_res"/>
  </logger>
   <logger name="abc2LogError" level="ERROR" additivity="false">
    <appender-ref ref="abc2_error"/>
  </logger>

   <appender name="requestQueue" class="ch.qos.logback.classic.AsyncAppender">
      <discardingThreshold>0</discardingThreshold>
      <queueSize>1000</queueSize>
      <appender-ref ref="abc_req"/>
    </appender>

    <appender name="responseQueue" class="ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold>0</discardingThreshold>
        <queueSize>1000</queueSize>
        <appender-ref ref="abc1_res"/>
    </appender>

    <appender name="errorQueue" class="ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold>0</discardingThreshold>
        <queueSize>500</queueSize>
        <appender-ref ref="abc2_error"/>
    </appender>
  <!-- 
  <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/> -->

  <root level="INFO">
    <appender-ref ref="stdout"/>
  </root>
</configuration>

But while checking in rolling files, there are so many log entries which are missing in the files.

Really need help in above case.

Any help/suggestion can really help me a lot!


Solution

  • Finally it's resolved!

    Issue: There were 2 JVM's trying to write in a common file.

    So simply by adding below in RollingFileAppender

    <prudent>true</prudent>
    

    And Removing file parameter in the configuration.

    <appender name="abc_req" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <prudent>true</prudent>
        <encoder>
          <pattern>%m%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
          <fileNamePattern>${log}/abc/request/request.log.%d{yyyy-MM-dd-HH}</fileNamePattern>
        </rollingPolicy>
      </appender>
    

    Also by fileNamePattern in rollingPolicy, I was able to give the correct filepath.