package crc.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); // Redirige System.out vers notre stream
    }

    public void stopCapture() {
        System.setOut(originalOut); // Restaure la console normale
        logArea.setText(logStream.toString()); // Affiche le texte capturé dans la fenêtre
    }
}
