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:
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] ].
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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a conflict for slf4j?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I renounced from using slf4j and used log4j - it seems to be better but still doesn't work. Please see the updated question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And here is the result of searching for .LoggerFactory http://pastebin.com/raw.php?i=N1k3pK4L
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And these are the dependencies from pom.xml http://pastebin.com/PAvkMsjE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.