Logging in Eclipse/OSGi plugins

后端 未结 2 1256
独厮守ぢ
独厮守ぢ 2020-12-23 15:07

I am starting to develop an Eclipse plugin (technically, an OSGi plugin) and one of the first problems I\'ve run into is that I can\'t seem to control the commons-logging ou

相关标签:
2条回答
  • 2020-12-23 15:23

    This is not an actual answer to your question, but you might find some clues in this set of articles by ekke.

    I suppose you read already "Using Log4J in Eclipse Equinox/OSGi":

    Did you launch an osgi session in a console mode ?

    java -jar org.eclipse.osgi_3.3.0.v20070530.jar -console -noExit -clean
    

    That way, you may test log4j in a pure osgi environment and check if it works there.

    Let use know if you find a solution (publish it as an answer), and I will vote it up ;)

    0 讨论(0)
  • 2020-12-23 15:34

    3 days later...

    I found the problem! There were two things I needed to do, first off, there was a problem with one MANIFEST.MF file:

    I had the following in the MANIFEST.MF for one bundle:

    Bundle-ClassPath: lib/jena.jar,
     .,
     org.apache.log4j-1.2.12.jar,
     lib/google-collect-snapshot.jar
    Import-Package: com.acme.client.translation,
     com.acme.translation.interfaces,
     com.acme.shared.osgi,
     com.acme.utilities
    

    That should have been this:

    Bundle-ClassPath: lib/jena.jar,
     .,
     lib/google-collect-snapshot.jar
    Import-Package: com.acme.client.translation,
     com.acme.client.translation.interfaces,
     com.acme.shared.osgi,
     com.acme.utilities,
     org.apache.log4j
    

    The key difference is that the log4j was being used as a package, when it should have been used as a bundle. (I had a log4j jar in my lib dir from when I had expected Log4j to "just work" with OSGi.) The jar does work, sort-of. It evidently found some eclipse-level log4j configuration, and made use of that. Since it was just a jar (not a bundle) it didn't make use of any fragments that could specify a custom logging config, which leads us to the other thing that had to happen:

    I needed to set up a bundle fragment to specify the logging config. This link from VonC gave me the info to do that. That entailed doing a number of things, unfortunately, the package with the incorrect MANIFEST.MF still had the log4j jar specified in the Bundle-ClassPath, and that seems to override the Import-Package list.

    I finally figured out what was going on when I needed to log in another bundle (I had just given up at this point, and went back to using logs at the Warn level and higher.) This new bundle couldn't find a logging config! (so then I had three bundles running in the same OSGi environment, each with different log4j behavior -- one using my fragment settings, another using some random Eclipse logging settings, and finally the new bundle that didn't have any logging config.) Detailed comparisons of these three bundles revealed the difference in the Manifest.MF files, and now they all use the fragment bundle.

    I owe a huge thanks to the authors of much of Eclipse Zone, VonC, Ekkes, and everyone in #eclipse on freenode for their help and patience :)

    0 讨论(0)
提交回复
热议问题