package hamming.Controllers;

import javax.swing.JTextArea;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class LogCapture {
    private JTextArea logArea;
    private PrintStream originalOut;
    private ByteArrayOutputStream logStream;

    public LogCapture(JTextArea logArea) {
        this.logArea = logArea;
        this.originalOut = System.out;
    }

    public void startCapture() {
        logStream = new ByteArrayOutputStream();
        PrintStream newOut = new PrintStream(logStream);
        System.setOut(newOut);
    }

    public void stopCapture() {
        System.setOut(originalOut);
        logArea.setText(logStream.toString());
    }
}
