When enabling traffic V1 logs by setting the artifactory.traffic.collectionActive=true or traffic V2 logs by setting the artifactory.traffic.v2.enabled=true in the artifactory.system.properties file located at $JFROG_HOME/artifactory/var/etc/artifactory/ in all the nodes of the cluster file and restarting the service, those logs won't be compressed and moved to the archived directory like other log files. This can clutter the $JFROG_HOME/artifactory/var/log directory and will consume extra disk space.
To change this behavior and enable log rotation where the v1/v2 traffic logs are automatically compressed and moved to the archived directory, please follow these steps:
Step 1:
Backup the $JFROG_HOME/artifactory/var/etc/artifactory/logback.xml file in case it will be required to revert the change at a later time.
Step 2: For Traffic v1 logs:
Comment out the default appender block from the $JFROG_HOME/artifactory/var/etc/artifactory/logback.xml file (Comments in XML start with "<! --" and end with "-->").
<!--
<appender name="TRAFFIC" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log.dir}/artifactory-traffic</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="org.artifactory.traffic.policy.TrafficTimeBasedRollingPolicy">
<FileNamePattern>${log.dir.archived}/artifactory-traffic.%d{yyyyMMdd}</FileNamePattern>
</rollingPolicy>
</appender>
-->
Add the following appender to automatically compress and move the v1 traffic logs to the archived directory.
<!-- custom traffic appender -->
<appender name="TRAFFIC" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log.dir}/artifactory-traffic.log</File>
<rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
<FileNamePattern>${log.dir.archived}/artifactory-traffic.%i.log.gz</FileNamePattern>
<compressLatest>true</compressLatest>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>25MB</MaxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%m%n</pattern>
</encoder>
</appender>
For Traffic v2 logs:
Add the following appender to automatically compress and move the v2 traffic logs to the archived directory.
<appender name="TRAFFIC_V2" class="org.artifactory.traffic.TrafficTimeBasedRollingFileAppender">
<intervalMs>900000</intervalMs>
<File>${log.dir}/artifactory-traffic-v2.log</File>
<encoder>
<pattern>%m%n</pattern>
</encoder>
<rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
<maxIndex>500</maxIndex>
<FileNamePattern>${log.dir.archived}/artifactory-traffic-v2-%i.log</FileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>25MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="org.artifactory.traffic.v2.TrafficLoggerV2" level="info" additivity="false">
<appender-ref ref="TRAFFIC_V2"/>
</logger>
Once the custom appender is added, traffic logs for v1 and v2 will be forwarded to the artifactory-traffic.log and artifactory-traffic-v2.log files, respectively. The size-based trigger policy of 25 MB is applied, and the logs will be compressed and moved to the $JFROG_HOME/artifactory/var/log/archived directory based on the policy. To modify the size, it is possible to update the value of MaxFileSize. After compression, the logs will follow the structure artifactory-traffic.<TIMESTAMP>.log.gz or artifactory-traffic-v2.<TIMESTAMP>.log.gz
No restart is required, and the configuration change will automatically be picked up by the JVM. However, in the case of HA, it's important to make the change on each node in the cluster, as the logback.xml file does not get propagated between the nodes.