简体   繁体   中英

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. 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.

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.

My solution is: I called the api call by using another thread like as 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{

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

}

So it prints the log immediately

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