How to create custom log file in atlassian JIRA Plugin?

Hello All,

we are developing a JIRA plug-in and we have to create separate log file for the plug-in.

I have added this log4j.properties:
#Define root logger options
log4j.rootLogger=INFO, file

#Define rolling file appender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=xyz.log
log4j.appender.file.Append=true
log4j.appender.file.ImmediateFlush=true
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=5
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %t %X{jira.username} [%c{4}] %m%n

#Define loggers
log4j.logger.com.journaldev.log4j=WARN, file, console
log4j.logger.com.journaldev.log4j.logic=DEBUG, file, console

#setting additivity
log4j.additivity.com.journaldev.log4j=false
log4j.additivity.com.journaldev.log4j.logic=false

In my java files I am initializing logger like this:
private static final Logger log = LoggerFactory.getLogger(XYZ.class);

but this is not creating separate file and instead it is logging all logs in atlassian-jira.log.

is there any other way possible to fulfill this requirement?

Thanks in advance.

Hello @hardik.shingala,

Kindly check Using your own log4j configuration for your plugin documentation. The answer to this similar developer community question might also help you out.

Cheers,
Ian

1 Like

Thank you @iragudo for the response.

I have tried this one previously but this logs everything in atlassian-jira.log and doesn’t create a new separate log file.

Hello @hardik.shingala,

I hope your are using slf4j api to get logger.
Did you try loading using log4j api?
org.apache.logging.log4j.Logger jdbcLogger = LogManager.getLogger(“XYZ.class”);

Thanks,
Kiran. M

@kiran.muthoju

Overriding Log4j appender to a different file using RollingFileAppender is not working when changed programatically.