为 Eclipse 插件添加日志框架:两种增强 Eclipse 日志功能的方法
2009-12-14 00:00:00 来源:WEB开发网
清单 1. TestPlugin 插件类中 PluginLogManager 的配置private static final String LOG_PROPERTIES_FILE = "logger.properties";
public void start(BundleContext context) throws Exception {
super.start(context);
configure();
}
private void configure() {
try {
URL url = getBundle().getEntry("/" + LOG_PROPERTIES_FILE);
InputStream propertiesInputStream = url.openStream();
if (propertiesInputStream != null) {
Properties props = new Properties();
props.load(propertiesInputStream);
propertiesInputStream.close();
this.logManager = new PluginLogManager(this, props);
this.logManager.hookPlugin(
TestPlugin.getDefault().getBundle().getSymbolicName(),
TestPlugin.getDefault().getLog());
}
}
catch (Exception e) {
String message = "Error while initializing log properties." +
e.getMessage();
IStatus status = new Status(IStatus.ERROR,
getDefault().getBundle().getSymbolicName(),
IStatus.ERROR, message, e);
getLog().log(status);
throw new RuntimeException(
"Error while initializing log properties.",e);
}
}
更多精彩
赞助商链接