Instructions

How can I write a user plugin log to a different log file

AuthorFullName__c
JFrog Support
articleNumber
000004315
ft:sourceType
Salesforce
FirstPublishedDate
2018-11-15T12:04:10Z
lastModifiedDate
2024-03-10T07:47:58Z
VersionNumber
4

For instance, consider you are writing your user plugin and you have added your log output methods as follows:

...
def newRepoPathString = id + "/" + itemInfo.getName()
                           log.warn("first element is: " + repoPathElements[0])
                           log.warn("layout.getModule() is: " + layout.getModule())
                           log.warn(newRepoPathString)

 

You can then go to your $ARTIFACTORY_HOME/etc/logback.xml file and add the following two snippets at the bottom of it:

1. A log appender, detailing the separate output file along with other settings:

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

<File>${artifactory.home}/logs/myPluginLogger.log</File>

<encoder>

<pattern>%date ${artifactory.contextId}[%thread] [%-5p] \(%-20c{3}:%L\) - %m%n</pattern>

</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">

<FileNamePattern>${artifactory.home}/logs/<appenderName>.%i.log</FileNamePattern>

<maxIndex>13</maxIndex>

</rollingPolicy>

<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">

<MaxFileSize>10MB</MaxFileSize>

</triggeringPolicy>

</appender>


 

2. The logger itself with an appender:

<logger name="<pluginName>" additivity="false">

<level value="warn" />

<appender-ref ref="<appenderName>"/>

</logger>
 

While the logger name attribute should be accompanied with your plugin's matching name, the appender-ref will direct the logger to a configured appender.

Final note, the logging level can be set to 4 different levels that we usually use, info / warn / debug / trace. In the example above, warn was used.