简体   繁体   English

Eclipse插件日志不会立即在控制台中的swt按钮onclick事件中打印

[英]Eclipse plugin log is not printed immediately in console in swt button onclick event

For print the log in console I used 为了打印我使用的登录控制台

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");

it print the log properly My problem is it doesn't print the log in swt onclick event immediately. 它可以正确打印日志我的问题是它不会立即在swt onclick事件中打印日志。 It print the log all process is completed. 它打印日志的所有过程均已完成。

my sample code is: 我的示例代码是:

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...");
        }

} }

Here the log messages are printed after complete the whole process of api invocation. 在完成api调用的整个过程之后,将在此处打印日志消息。

How do I print the log immediately of execution? 如何立即打印执行日志?

Try using 尝试使用

new PrintStream(stream, true)

for the PrintStream constructors to get the stream flushed quicker. PrintStream构造函数更快地刷新流。

My solution is: I called the api call by using another thread like as button_Ok.addSelectionListener(new SelectionListener() { 我的解决方案是:我通过使用另一个线程(如button_Ok.addSelectionListener(new SelectionListener(){

    @Override
    public void widgetSelected(SelectionEvent e) {
        log.info("Before invoking the api call");
        Thread thread = new Thread(new createDesigns());
        thread.start();
     }

} }

In another class 在另一堂课

public class createDesigns implements Runnable{ 公共类createDesigns实现了Runnable {

@Override
public void run() {
          CreateDesign create=new CreateDesign();
          boolean status=create.createDesign();//api invoked
}

} }

So it prints the log immediately 因此它立即打印日志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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