How to enable logging to write in new log file ?
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Instead of logging in atlassian-jira.log, adding logging statements in a separate file is needed while doing custom implementation or scripting.
Environment
9.5 onwards
Solution
Based on the existing KB article Migrating custom logging configurations to Log4j 2, below steps have been derived and could be followed.
Step#1: Take backup of your existing log4j2.xml
located under atlassian-jira-software-9.5.0-standalone/atlassian-jira/WEB-INF/classes
Step#2: Create Separate JiraHomeAppender for e.g filelogtest in log4j2.xml
<JiraHomeAppender name="filelogtest"
fileName="atlassian-jiratest.log"
filePattern="atlassian-jiratest.log.%i">
<PatternLayout alwaysWriteExceptions="false">
<Pattern>${StackTraceFilteringPattern}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20480 KB"/>
</Policies>
<DefaultRolloverStrategy fileIndex="min" max="10"/>
</JiraHomeAppender>
Step#3: Add AppenderRef for e.g filelogtest
<Logger name="com.atlassian.jira.util.log.LogMarker" level="INFO" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="filelog"/>
<AppenderRef ref="filelogtest"/>
<AppenderRef ref="httpaccesslog"/>
<AppenderRef ref="httpdumplog"/>
<AppenderRef ref="sqllog"/>
<AppenderRef ref="querydsllog"/>
<AppenderRef ref="slowquerylog"/>
<AppenderRef ref="slowsqlquerylog"/>
<AppenderRef ref="xsrflog"/>
<AppenderRef ref="securitylog"/>
<AppenderRef ref="outgoingmaillog"/>
<AppenderRef ref="incomingmaillog"/>
<AppenderRef ref="remoteappssecurity"/>
<AppenderRef ref="apdexlog"/>
</Logger>
Step#4: Create Logger for package
<Logger name="com.mytest.jira" level="INFO" additivity="false">
<AppenderRef ref="filelogtest"/>
</Logger>
Step#5: Restart Jira node for the above changes to take effect.
As a result of the above configuration, a separate file with name atlassian-jiratest.log
would be created upon restart and the loggings would get added to it while accessing the logger in scripts.
import org.apache.log4j.Logger
def log=Logger.getLogger("com.mytest.jira");
log.warn("My Test logger..");