Using the Grails framework how would one go about reading console output. What I mean is I have a java library in my grails app that outputs(system.out.println(\"x\")) to the co
You can redirect the output with the System.setOut() method. Here is a quick example that redirects System.out to a text pane after five seconds:
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Date;
public class TextCapture {
public static void main(String[] args) throws Exception {
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final JTextArea jta = new JTextArea();
jta.setPreferredSize(new Dimension(400, 200));
jf.getContentPane().add(jta);
jf.pack();
jf.setVisible(true);
OutputStream textOS = new OutputStream() {
@Override
public void write(int b) throws IOException {
jta.setText(jta.getText() + ((char)b));
}
};
for(int i = 0; i < 20; i++) {
Thread.sleep(1000);
if(i == 5) {
System.setOut(new PrintStream(textOS));
}
System.out.println(String.valueOf(new Date()));
}
}
}
We can use log4j configuration, write your app logs in a file, keep reading same file with your app. This should suffice your requirement. Read more on http://grails.org/doc/latest/guide/conf.html section 5.1.2 Logging