ARTIFACTORY: How to configure maxHistory in Artifactory’s logback.xml

ARTIFACTORY: How to configure maxHistory in Artifactory’s logback.xml

AuthorFullName__c
Derek Pang
articleNumber
000005520
ft:sourceType
Salesforce
FirstPublishedDate
2022-12-22T08:47:05Z
lastModifiedDate
2022-12-22
VersionNumber
5

Artifactory has a logback.xml for the logs starting with ‘artifactory’ (directory location example: $ART_HOME/etc/artifactory/logback.xml). For other logs (besides access*.log you can edit its configuration in Artifactory’s system.yaml).

You may have a use case of wanting to change the default rotation of the logs to be able to have a time based rolling policy instead. For example, utilizing a maxHistory configuration.

The default maxHistory is for time based rolling policies and is not available in the sizeAndIntervalTriggeringPolicy from Jfrog's custom policy (org.jfrog.common.logging.logback.triggering.SizeAndIntervalTriggeringPolicy).

If you wish for the maxHistory parameter you will have to reconfigure the logback.xml loggers to utilize a different rolling policy but note that it uses different configurations and more adjustments may be needed. (For example, maxIndex configuration is not used in time based rolling policies.)
i.e. 
Default configuration snippet in the logback.xml:

    <appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${log.dir}/artifactory-access.log</File>
        <rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
            <FileNamePattern>${log.dir.archived}/artifactory-access.%i.log.gz</FileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%date{yyyy-MM-dd'T'HH:mm:ss.SSS, UTC}Z [%-16X{uber-trace-id}] %m%n</pattern>
        </encoder>
        <triggeringPolicy class="org.jfrog.common.logging.logback.triggering.SizeAndIntervalTriggeringPolicy">
            <MaxFileSize>25MB</MaxFileSize>
        </triggeringPolicy>
    </appender>


Adjusted configuration snippet for adding a Time Based Rolling Policy :
<appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${log.dir}/artifactory-access.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">           
        <FileNamePattern>${log.dir.archived}/artifactory-access-%d{yyyy-MM-dd}.%i.log.gz</FileNamePattern>
            <maxFileSize>300MB</maxFileSize>
            <maxHistory>10</maxHistory>
            <totalSizeCap>5GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%date{yyyy-MM-dd'T'HH:mm:ss.SSS, UTC}Z [%-16X{uber-trace-id}] %m%n</pattern>
        </encoder>
    </appender>