Log4j and Eclipse / Osgi / Equinox (and a little bit of Xtext, too).

There are several articles on the web on how to use log4j with Eclipse applications. However, using these I still ran into a few problems so I’d like to add to that information.

To use log4j in Eclipse application, you have to provide a fragment with your own log4j.properties or log4j.xml. How this is done can be easily found on the web by searching for “log4j Eclipse”. If all works fine, perfect. However, if it doesn’t, you have to do some troubleshooting.

The fragment approach works by adding your own fragment to theĀ  class path of the log4j bundle. It gets ugly, when yours is not the only fragment that contributes to theĀ  class path. Then it depends on who is first (and I did not find a way to specify the priority of fragments). If you have Xtext in your target platform then this will contribute as well and you might run into problems.

This can be fixed by removing the org.eclipse.xtext.logging bundle from your target platform. If it still does not work, then you might try to set the -Dlog4j.debug property in your run configuration. It prints out information about the configuration file, if you are lucky (e.g. it does not, for some reason, if the Xtext fragment is in there).

If that did not work, you might set a breakpont for log4j’s

. Step through the calls it makes, at some point you will see the bundle variable where it tries to load the config and that will be the fragment that contributes the log4j.properties.

Leave a Reply

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