Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirecting log4j statements to custom console in java
    text
    copied!<p>The following class uses a JInternalFrame holding a Textarea that displays all the redirected println and err statements. </p> <pre><code>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 &lt; 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); } } } </code></pre> <p>This class only redirects the sysout and syserr statements. What modification should I make in the code to redirect the logger statements into the textarea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload