Logback stopped logging after splitting shared config file

222 views Asked by At

I have introduced logback to a system that uses muliple JVM's. The system is in fact two seperate projects, and previously they shared an external configuration file that looked like this:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true">
        <!-- general console appender -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d{HH:mm:ss.SSS,CET}  %-5level [%file:%line] - %msg%n</pattern>
            </layout>
        </encoder>
        <target>System.out</target>
    </appender>

        <!-- Project1 appenders -->
    <appender name="project1ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <prudent>true</prudent>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/data/logs/project1/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 100MB -->
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- keep 90 days' worth of history -->
            <maxHistory>90</maxHistory>
        </rollingPolicy>

        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
            </layout>
        </encoder>
    </appender>

    <appender name="project1ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">

        <prudent>true</prudent>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/data/logs/project1/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 100MB -->
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- keep 90 days' worth of history -->
            <maxHistory>90</maxHistory>
        </rollingPolicy>

        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>[%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] %m%n</Pattern>
            </layout>
        </encoder>
    </appender>

        <!-- project1 loggers -->
    <logger name="logger1project1" additivity="false">
        <level value="ALL"/>
        <appender-ref ref="project1ConnectorAppender"/>
    </logger>

    <logger name="logger2project1">
        <level value="INFO"/>
        <appender-ref ref="project1ApplicationAppender"/>
    </logger>

    <logger name="logger3project1">
        <level value="INFO"/>
        <appender-ref ref="project1ApplicationAppender"/>
    </logger>

        <!-- project2 appenders -->
    <appender name="project2ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <prudent>true</prudent>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/data/logs/project2/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 100MB -->
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- keep 90 days' worth of history -->
            <maxHistory>90</maxHistory>
        </rollingPolicy>

        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
            </layout>
        </encoder>

    </appender>

    <appender name="project2ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">

        <prudent>true</prudent>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/data/logs/project2/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 100MB -->
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- keep 30 days' worth of history -->
            <maxHistory>90</maxHistory>
        </rollingPolicy>

        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>[%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] %m%n</Pattern>
            </layout>
        </encoder>
    </appender>

        <!-- project2 loggers -->
    <logger name="logger1project2" additivity="false">
        <level value="OFF"/>
        <appender-ref ref="project2ConnectorAppender"/>
    </logger>

    <logger name="logger2project2">
        <level value="INFO"/>
        <appender-ref ref="project2ApplicationAppender"/>
    </logger>

    <root>
        <level value="INFO"/>
        <appender-ref ref="console"/>
    </root>

</configuration>

This worked like it should. Then we introduced a new logger that had the same name in both projects, but we still wanted separate files for each project, so we had to split the config file into two. When we did that, one of the projects stopped logging, and i cannot understand why. This is the configuration file for the project that stopped:

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

  <!-- general console appender -->
  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%d{HH:mm:ss.SSS,CET}  %-5level [%file:%line] - %msg%n</pattern>
      </layout>
    </encoder>
    <target>System.out</target>
 </appender>

  <!-- project2 appenders -->
  <appender name="project2ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <prudent>true</prudent>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>/data/logs/project2/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 100MB -->
        <maxFileSize>100MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <!-- keep 90 days' worth of history -->
      <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
      </layout>
    </encoder>
  </appender>

  <appender name="project2ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <prudent>true</prudent>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>/data/logs/project2/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 100MB -->
        <maxFileSize>100MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <!-- keep 90 days' worth of history -->
      <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>[CBM - %-5p] [%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"}] %m%n</pattern>
      </layout>
    </encoder>
  </appender>

  <appender name="project2PayloadAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <prudent>true</prudent>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>/data/logs/project2/payload/%d{yyyy-MM-dd}/payload.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 100MB -->
        <maxFileSize>100MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <!-- keep 90 days' worth of history -->
      <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>[CBM - %-5p] [%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"}] %m%n</pattern>
      </layout>
    </encoder>
  </appender>

  <!-- project2 loggers -->
  <logger name="logger1project2" additivity="false">
    <level value="INFO" />
    <appender-ref ref="project2ConnectorAppender" />
  </logger>
  <logger name="newlogger" level="TRACE" additivity="false">
    <appender-ref ref="project2PayloadAppender" />
  </logger>
  <logger name="logger2project2" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="project2ApplicationAppender" />
  </logger>
  <root>
    <level value="INFO" />
    <appender-ref ref="project2ApplicationAppender" />
  </root>
</configuration>

I have added the specific paths in the java options in each JVM like this:

-Dlogback.configurationFile={config path}

They were previously the same for each project, but are now separate.

One other piece of information is that the system is deployed on two servers, each with a copy of the config files. And it works perfectly on one of the servers, even tho the config files and deployment process are identical.

I have looked for solutions for an entire workday without any luck.

This is in a live production environment, so i cannot simply do a new deploy of the system, or read status messages from console.

We have test systems, but the issue is not present there, even tho the config files are similar.

Thanks for any answers in advance!

0

There are 0 answers