为了打印我使用的控制台中的日志
MessageConsole console = new MessageConsole("System Output", null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
MessageConsoleStream stream = console.newMessageStream();
System.setOut(new PrintStream(stream));
System.setErr(new PrintStream(stream));
String rootPath="D:/luna/sampleproject";
System.setProperty("file.log",rootPath+"logs/log_console.log");
正确打印日志 我的问题是它不会立即打印 swt onclick 事件中的日志。它打印日志所有过程已完成。
我的示例代码是:
button_Ok.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
log.info("Before invoking the api call");
CreateDesign create=new CreateDesign();
boolean status=create.createDesign();//api invoked
log.info("Api invokoing is completed...");
}
}
这里是整个api调用过程完成后打印的日志消息。
如何立即打印执行日志?
最佳答案
尝试使用
new PrintStream(stream, true)
用于 PrintStream
构造函数更快地刷新流。
关于java - Eclipse 插件日志不会立即打印在 swt 按钮 onclick 事件的控制台中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37435191/