简体   繁体   中英

How to log starting of Eclipse plug-ins / OSGi bundles?

In an Eclipse RCP application, how can I automatically log each plug-in as it is being started?

I know about these, but am looking for something more akin to Java's -verbose:class :

  • OSGi console's ability to query the current set of plug-ins.
  • Handcoding a logging call in each plug-in's activator.

This feels like an option that should already exist. Seems like there should be an option to automatically log bundle-state changes for plug-ins. But I haven't found anything after a quick search online and in books. Am I missing something obvious?

Bundle state changes are already logged by OSGi to the Log Service. Please refer to chapter 101 of the OSGi Compendium specification.

If you want to log bundle start events using some specific mechanism other than the standard Log Service, then you can write a BundleListener . The trick is to get your listener registered early enough so you catch all the other bundles being started (obviously if the bundle containing the listener is started last then it will not be able to see these events).

If you are in control of the top-level application then you should be able to register the listener from the OSGi launcher, ie using the BundleContext of the system bundle itself. But the launcher is usually in control of starting bundles anyway, meaning that the time to log the start of a bundle is when your code calls start() on each of them! It all depends on how your application is structured.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM