Skip to main content

This works for me:

    <appender name="rollingCoreLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.folder}/cd_core.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <maxHistory>${log.history}</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>1MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>${log.pattern}</pattern>
    </encoder>
    <prudent>true</prudent>
</appender>

I think inserting the node timeBasedFileNamingAndTriggeringPolicy inside the rollingPolicy and using the %i as the index of the numbered files.

If you only want to use a Size triggering, then the previous solution of Jonathan works only if the rolling Policy is "FixedWindowRollingPolicy", not the TimeBasedRollingPolicy used by the logbacks of Tridion examples.

This works for me:

    <appender name="rollingCoreLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.folder}/cd_core.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <maxHistory>${log.history}</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>1MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>${log.pattern}</pattern>
    </encoder>
    <prudent>true</prudent>
</appender>

I think inserting the node timeBasedFileNamingAndTriggeringPolicy inside the rollingPolicy and using the %i as the index of the numbered files.

If you only want to use a Size triggering, then the previous solution of Jonathan works only if the rolling Policy is "FixedWindowRollingPolicy", not the TimeBasedRollingPolicy used by the logbacks of Tridion examples.

This works for me:

<appender name="rollingCoreLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <fileNamePattern>${log.folder}/cd_core.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
    <maxHistory>${log.history}</maxHistory>
    <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
      <maxFileSize>1MB</maxFileSize>
    </timeBasedFileNamingAndTriggeringPolicy>
  </rollingPolicy>
  <encoder>
    <pattern>${log.pattern}</pattern>
  </encoder>
  <prudent>true</prudent>
</appender>

I think inserting the node timeBasedFileNamingAndTriggeringPolicy inside the rollingPolicy and using the %i as the index of the numbered files.

If you only want to use a Size triggering, then the previous solution of Jonathan works only if the rolling Policy is "FixedWindowRollingPolicy", not the TimeBasedRollingPolicy used by the logbacks of Tridion examples.

Source Link
Raúl Escudero
  • 3.8k
  • 16
  • 26

This works for me:

    <appender name="rollingCoreLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.folder}/cd_core.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <maxHistory>${log.history}</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>1MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>${log.pattern}</pattern>
    </encoder>
    <prudent>true</prudent>
</appender>

I think inserting the node timeBasedFileNamingAndTriggeringPolicy inside the rollingPolicy and using the %i as the index of the numbered files.

If you only want to use a Size triggering, then the previous solution of Jonathan works only if the rolling Policy is "FixedWindowRollingPolicy", not the TimeBasedRollingPolicy used by the logbacks of Tridion examples.