How to use logging from inside Jira plugins?

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2012

What is the proper way of logging from inside Jira (5.x) plugins?

I found at least two articles and I am not sure which approach is the correct one.

Update: I am looking to obtain a proper and well documented way of implementing logging in Jira plugins, one that will have to match the following requirements:

  • Sample code to add to your plugin (including modifications to atlassian-plugin.xml or pom.xml, if needed)
  • Logged messaged should be visible inside atlassian-jira.log file
  • Not to interfere with logging from other plugins - I am asking this because the approach of inserting a log4j.properties file with your plugin seems to work agains this.
  • Be able to see all messages from your plugin when you run in development mode (example atlas-run)
  • Be able to see warnings or above when running on Jira, and this without having to tune Jira logging configuration.

Where I got so far:

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
...
public class MyJiraServlet extends HttpServlet {

    private static final Logger log = LogManager.getLogger("atlassian.plugin");
...
}

log.info("MyPlugin init"); // should see this on devel
log.error("MyPlugin error");  // should see this even on production
...
 
The problem is that now I goet tons of errors in the console, which I suppose should be real logs from my plugin

 

[INFO] [talledLocalContainer] log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
[INFO] [talledLocalContainer] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
[INFO] [talledLocalContainer] log4j:ERROR [109.0] whereas object of type 
[INFO] [talledLocalContainer] log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
[INFO] [talledLocalContainer]   delegate: false
[INFO] [talledLocalContainer]   repositories:
[INFO] [talledLocalContainer]     /WEB-INF/classes/
[INFO] [talledLocalContainer] ----------> Parent Classloader:
[INFO] [talledLocalContainer] org.apache.catalina.loader.StandardClassLoader@30fffd2c
[INFO] [talledLocalContainer] ].
[INFO] [talledLocalContainer] log4j:ERROR Could not instantiate appender named "console".
[INFO] [talledLocalContainer] log4j:ERROR A "com.atlassian.jira.logging.MultiTenantJiraHomeAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
[INFO] [talledLocalContainer] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
[INFO] [talledLocalContainer] log4j:ERROR [109.0] whereas object of type 
[INFO] [talledLocalContainer] log4j:ERROR "com.atlassian.jira.logging.MultiTenantJiraHomeAppender" was loaded by [WebappClassLoader
[INFO] [talledLocalContainer]   delegate: false
[INFO] [talledLocalContainer]   repositories:
[INFO] [talledLocalContainer]     /WEB-INF/classes/
[INFO] [talledLocalContainer] ----------> Parent Classloader:
[INFO] [talledLocalContainer] org.apache.catalina.loader.StandardClassLoader@30fffd2c
[INFO] [talledLocalContainer] ].
[INFO] [talledLocalContainer] log4j:ERROR Could not instantiate appender named "filelog".
[INFO] [talledLocalContainer] log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
[INFO] [talledLocalContainer] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
[INFO] [talledLocalContainer] log4j:ERROR [109.0] whereas object of type 
[INFO] [talledLocalContainer] log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
[INFO] [talledLocalContainer]   delegate: false
[INFO] [talledLocalContainer]   repositories:
[INFO] [talledLocalContainer]     /WEB-INF/classes/
[INFO] [talledLocalContainer] ----------> Parent Classloader:
[INFO] [talledLocalContainer] org.apache.catalina.loader.StandardClassLoader@30fffd2c
[INFO] [talledLocalContainer] ].

 

 

3 answers

2 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2012

You can use the approach used in the listener example. Atlassian plugins mostly follow that.

And yes, INFO level is filtered. WARN is the default. You can change it to INFO temporarily under Administration > Logging & Profiling or permentantly under log4j.properties.

Better to change only for your package.

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2012

I followed your advise but I get an error now, at runtime:

ERROR admin 829x688x1 yjfxoz 10.80.118.154 /plugins/servlet/testrun/ [atlassian.plugin.servlet.DefaultServletModuleManager] Unable to create servlet
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.myjiraplugin.MyJiraServlet': Instantiation of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/WebappClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
[INFO] [talledLocalContainer] 	at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:152)
[INFO] [talledLocalContainer] 	at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:115)

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2012

Is there a conflict for slf4j?

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2012

I renounced from using slf4j and used log4j - it seems to be better but still doesn't work. Please see the updated question.

Kannan S January 27, 2014

Hi Jobin,

If i use Logger in my class, when i do a mvn package (in eclipse) it complains about the missing class files. So i added the dependency. But i guess this is what is stopping the messages from logging in the atlassian-jira.log. How to i remove the dependency and still compile the code?

0 votes
Al Johnson September 18, 2019

This stuff is still borken!!!!

Al Johnson March 23, 2020

Still broken

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2012

I have seen the errors that is reported in your console. This happens when there is a conflict of log4j jar.

For example, it is there both in JIRA_INSTALL_DIR/lib and in WEB-INF/lib or there is a plugin which has log4j embedded in it (because of a meven dependency).

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2012

Here is the result of looking for jar files with this class http://pastebin.com/raw.php?i=8bA5WK6i

Did I mention that I removed the target directory and I just run atlas-run after this, testrun is my plugin.

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2012

And here is the result of searching for .LoggerFactory http://pastebin.com/raw.php?i=N1k3pK4L

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2012

And these are the dependencies from pom.xml http://pastebin.com/PAvkMsjE

Suggest an answer

Log in or Sign up to answer