Background
In one of our earlier post we saw how to create a Jira cloud plugin -
You can similarly create a plugin for Jira server. Though these tutorials can help you develop the plugin what I felt inadequate is documentation around logging. Logging is very important in any code you write. It helps you understand the flow and find the issues in case it arises. In this post we will see how logging works for Jira.
Jira plugin logs should be part of atlassian-jira.log file.
Again note changes done from this admin console are temporary and do not persist over server restarts. To make permanent changes you need to edit file -
<your-addon-dir>/target/jira/webapp/WEB-INF/classes/log4j.properties
You can similarly create a plugin for Jira server. Though these tutorials can help you develop the plugin what I felt inadequate is documentation around logging. Logging is very important in any code you write. It helps you understand the flow and find the issues in case it arises. In this post we will see how logging works for Jira.
How to enable logging in your Jira plugin
Jira uses log4j for runtime logging so you do not have to do anything out of the box to set the logging framework. If you are using atlassian sdk you can straight away start using slf4j logging in your code (It will use log4j underneath). A sample example could be -
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyClass { private static final Logger log = LoggerFactory.getLogger(MyClass.class); public void myMethod() { ... log.info("Log a message here"); ... } }
And that's it you can see those logs in your log file. Log file is located at following location -
- <your_addon_dir>/target/jira/home/log
-rw-rw-r-- 1 athakur athakur 0 Dec 27 14:31 atlassian-greenhopper.log -rw-rw-r-- 1 athakur athakur 1248201 Dec 29 00:40 atlassian-jira.log -rw-rw-r-- 1 athakur athakur 2558 Dec 29 00:39 atlassian-jira-security.log -rw-rw-r-- 1 athakur athakur 223 Dec 27 14:33 atlassian-jira-slow-queries.log -rw-rw-r-- 1 athakur athakur 18217 Dec 28 18:39 atlassian-servicedesk.log
Jira plugin logs should be part of atlassian-jira.log file.
Logging levels
There are five logging levels available in log4j:
'DEBUG', 'INFO', 'WARN', 'ERROR' and 'FATAL'. Each logging level provides more logging information that the level before it:
- 'DEBUG'
- 'INFO'
- 'WARN'
- 'ERROR'
- 'FATAL'
'DEBUG' provides the most verbose logging and 'FATAL' provides the least verbose logging. The default level is WARN, meaning warnings and errors are displayed. Sometimes it is useful to adjust this level to see more detail.
You can see these configurations in a file called log4j.properties. Localtion of this file is -
- <your-addon-dir>/target/jira/webapp/WEB-INF/classes/log4j.properties
In this file you should see a line saying -
Alternatively you can temporarily change the debug level or add a new log level for a particular package using Jira admin console. Go to System -> Logging and profiling
# To turn more verbose logging on - change "WARN" to "DEBUG" log4j.rootLogger=WARN, console, filelog, cloudAppenderJust change the WARN to DEBUG if you want to see debug logs.
Alternatively you can temporarily change the debug level or add a new log level for a particular package using Jira admin console. Go to System -> Logging and profiling
Here you can see default logger set to warn. You can change this to debug or add a new package with corresponding log level.
Again note changes done from this admin console are temporary and do not persist over server restarts. To make permanent changes you need to edit file -
<your-addon-dir>/target/jira/webapp/WEB-INF/classes/log4j.properties
No comments:
Post a Comment