将log4j语句重定向到Java中的自定义控制台

| 下列类使用JInternalFrame持有一个Textarea,该区域显示所有重定向的println和err语句。
public class ConsoleFrame extends JInternalFrame
{
  JTextArea outArea = new JTextArea(10,100);
  static JInternalFrame cons;
  public ConsoleFrame() 
  {
    outArea.setLineWrap(true);
    JScrollPane pain = new JScrollPane(outArea);
    //pain.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    this.add(pain);
    this.setVisible(true);
    this.setSize(1000,400); 
    this.setTitle(\"Groovy Console\");
    this.closable = false;
    this.maximizable = false;
    this.isSelected = true;
    this.resizable = false;
    BasicInternalFrameUI ui = (BasicInternalFrameUI)this.getUI();
    Component north = ui.getNorthPane();
    MouseMotionListener[] actions =
    (MouseMotionListener[])north.getListeners(MouseMotionListener.class);

    for (int i = 0; i < actions.length; i++)
    north.removeMouseMotionListener( actions[i] );

    this.setFocusable(false);    
 //logger
    System.setErr(new PrintStream(new JTextAreaOutputStream(outArea)));
    System.setOut(new PrintStream(new JTextAreaOutputStream(outArea)));

    setConsole(this);
  }


  static public JInternalFrame getConsole(){
      return cons;
  }
  public void setConsole(JInternalFrame console){
      cons = console;
  }
  public class JTextAreaOutputStream extends OutputStream {
    JTextArea ta;

    public JTextAreaOutputStream(JTextArea t) {
      super();
      ta = t;
    }

    public void write(int i) {
      ta.append(Character.toString((char)i));
    }

    public void write(char[] buf, int off, int len) {
      String s = new String(buf, off, len);
      ta.append(s);
    }

  }

}
此类仅重定向sysout和syserr语句。我应该在代码中进行哪些修改以将logger语句重定向到textarea?     
已邀请:
您应该实现自定义Log4J记录器。有非常有用的基类可以扩展。我建议使用
org.apache.log4j.WriterAppender
。     
在替换它们之前,Log4J记录器可能会获取对System.out和System.err的引用。因此,您可以实现自定义的Appender,也可以尝试击败Log4J。如果您可以控制启动,则后者可能是可行的。     

要回复问题请先登录注册