解决方法
您可以向Logger添加一个附加的Appender.使用
WriterAppender写入一个StringWriter,然后将TextArea的内容更改为StringWriter#toString()的值,
示例代码:
public static void main(String[] args) { Logger logger = Logger.getLogger("logger"); Layout layout = new PatternLayout(); StringWriter stringWriter = new StringWriter(); WriterAppender writerAppender = new WriterAppender(layout,stringWriter); logger.addAppender(writerAppender); TextArea textArea = new TextArea(); logger.error("test"); //if(stringWriter changed){// compare to old TextArea-content? textArea.setText(stringWriter.toString()); //} //System.out.println(stringWriter.toString()); }
您需要找到一个智能的方式来更新您的TextArea,具体取决于logLevel,如果StringWriter的内容更改.