I want to write my own log file for my jira plugin

Hi Experts,

Kindly help me to create my own log file for my jira plugin. Now i placed my log4j.properties file in src/main/resources and my rest api of jira plugin i wrote below code but it is not creating any log file inside
log folder.
LOGGER.info(“calling getJiraActivity api”);

log4j.properties file details:

Root logger option

log4j.rootLogger=INFO, file

Direct log messages to a log file

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=${catalina.home}/logs/XYZConnector.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Kindly help me in above issue:

You would either have to update the log4j configuration within JIRA manually (or tell your users how to) OR update the configuration programatically (haven’t tested this one but found it on the google machine):

You could do this on component using the LifeCycleaware interface (onStart to configure onStop to tear it down) - see Shared Application Access Layer API 3.0.0 API

Word of caution though: If you’re doing this on a commercial add-on - your user base may care about log rotations etc so you’ll want to make sure you can configure that piece.

1 Like

In my bitbucket server plugins I use logback. Create a component with a custom loggerfactory that scans the classpath for a logback.xml file. you’ll need to stop the appenders before you re-initialize or you’ll have an additional file every time your plugin is re-installed. I don’t have users so…

1 Like

Kindly share the link of that code there you used logback or any example for reference so i can refer that. Thank you Justin.

Thanks Daniel and kindly share any example of reference .

I can’t really give you mine but I googled a bit and found you this: https://github.com/palantir/stash-codesearch-plugin
They pretty much do the same thing. I don’t see how they deal with creating multiple appenders. I search for any appenders with the same name and stop them before initializing. If I don’t I end up with an additional log file every time I re-install my plugin.

Just to add texture to the other excellent answers, the Atlassian SDK documentation has some relevant info under “Using your own log4j configuration for your plugin”, including this:

“A plugin specific log4j.properties file does not get picked up using this method once you deploy your plugin to another stand alone server. It only works using atlas-run or atlas-debug.”