Jira Plugin & Log4J

I came across this problem lately when I was working on a Jira plugin. A Jira plugin does not rely on a OSGi container or some similar plugin framework. The plugin consists mainly of a jar file that gets deployed with (I mean inside…) the Jira Java EE web application.

Logging is an issue in such an environment: the surrounding application configures the logging API – there is no way to provide log4j configuration fragments.

The best way I found to solve the problem was (again) to use the native logging API to the configuration manually. Since Jira has already setup the logging API, all I needed was to add some categories with some levels, or, if I need to, create my own appenders. That’s all possible with the API exposed by log4j.

So I created a Jira component module inside my plugin that does the configuration magic. Jira uses PicoContainer (lightweight, embedable, configurable, POJO based IOC/DI component runtime) as the runtime for their own and for components provided by plugins. As components get initialized along with the Jira application it is good place to implement the required logging configuration:

Just by adding this component to the atlassian-plugin.xml in my plugin I solved my problems with distributed logging configuration:

One thought on “Jira Plugin & Log4J”

  1. I can’t see how the logging of the jira plugin could be configured by the global log4j.properties file. You need to rebuild every time you want to change the log level.
    Can the plugin (classloader) count on the log4j.properties resource file being available?
    I have the following problem : the jira plugin v2 classload does not “see” the global log4j.properties file. It works fine with a local /src/main/resources/log4j.properties file though. Again – this gets packaged into the plugin jar and log levels can’t be changed outside the plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *