Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EclipseRCP将来自其他插件的日志语句添加到日志插件中_Eclipse_Logging_View_Rcp - Fatal编程技术网

EclipseRCP将来自其他插件的日志语句添加到日志插件中

EclipseRCP将来自其他插件的日志语句添加到日志插件中,eclipse,logging,view,rcp,Eclipse,Logging,View,Rcp,我想在EclipseRCP应用程序中显示一些日志信息。为此,我在一个单独的插件(singleton)中创建了一个Eclipse视图。这是我迄今为止得到的代码: public class Console extends ViewPart { private StyledText text; public Console() {} @Override public void createPartControl(Composite parent) {

我想在EclipseRCP应用程序中显示一些日志信息。为此,我在一个单独的插件(singleton)中创建了一个Eclipse视图。这是我迄今为止得到的代码:

public class Console extends ViewPart {    
    private StyledText text;

    public Console() {}

    @Override
    public void createPartControl(Composite parent) {
        text = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL
                | SWT.V_SCROLL);
    }

    @Override
    public void setFocus() {
        this.text.setFocus();
    }

    public void log(String message){
        this.text.append(message);
    } 
}
以及配置:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
  <extension
        point="org.eclipse.ui.views">
     <view
           category="org.myApp.ui.category.myApp"
           class="org.myApp.ui.log.Console"
           icon="icons/log.png"
           id="org.myApp.ui.view.console"
           name="Console"
           restorable="true">
     </view>
     <category
           id="org.myApp.ui.category.myApp"
           name="myApp">
     </category>
  </extension>
</plugin>

现在,我想将来自其他插件的消息记录到
StyledText
实例。最方便的方法是什么


我试过这个,很方便,但速度很慢。我真的很感谢你的帮助:)谢谢

是一系列关于登录OSGI的优秀文章。

以下是我的控制台部分的后期构造方法。基本上,它会设置一个新的System.out对象并侦听它

@PostConstruct
public void postConstruct(Composite parent) {

    System.out.println("[Console Part] ** Post Construct **"); 

    txtConsole = new Text(parent, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);

    out = new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            if( txtConsole.isDisposed() )
                return;
            txtConsole.append(String.valueOf((char) b));
        }
    };

    // keep the old output stream
    final PrintStream oldOut = System.out;

    System.setOut(new PrintStream(out));
    txtConsole.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            System.setOut(oldOut);
        }
    });
}

谢谢你的链接。我看了一下,我不确定这是否符合我的需要。我只是想在某个视图中为用户显示一些信息。我个人认为传统的日志记录中,带有级别的消息被添加到日志文件中作为开发人员的信息。您可以使用org.eclipse.core.runtime.ILogListener界面连接eclipse日志。有没有一种简单的方法可以将
字符串传递给某个视图实例呢。