简体   繁体   中英

Eclipse PDE logging missing method

So I am reading this FAQ :

It mentions getLog() method which is not available. My current class is basically extending AbstractHandler . How am I supposed to use this?

If you let Eclipse create the Activator class for you and you specified the 'This plug-in will make contributions to the UI' option then the class will look something like:

public class Activator extends AbstractUIPlugin {

    // The shared instance
    private static Activator plugin;

    public Activator() {
    }

    @Override
    public void start(final BundleContext context) throws Exception {
        super.start(context);
        plugin = this;
    }

    @Override
    public void stop(final BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    public static Activator getDefault() {
        return plugin;
    }
}

You can then call

ILog log = Activator.getDefault().getLog();

to access the log interface

From the FAQ: " The log for a plug-in is accessed from the plug-in's class, using getLog inherited from Plugin ". This means, you need to access the log from your own plugin's class.

So, essentially, you'll need to add in your AbstractHandler following:

ILog log = MyPluginClass.getInstance().getLog();

Remember, that getInstance() is not a standard method, but plugins are supposed to work as singletons. So, you maybe need to add this method.

The method is documented in the Eclipse Help which is a good reference documentation if you have any questions regarding Eclipse and its implementation.

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