为什么我会丢失控制台输出?

Why do I lose the console output?

我在 JUnit 测试中有这段代码:

public class CvsCommandTest {
...
    @Test
    public void test() {
        PServerConnection con = new PServerConnection(root);
        GlobalOptions globalOptions = new GlobalOptions();
        globalOptions.setCVSRoot(root.toString());

        Client client = new Client(con, new StandardAdminHandler());
        client.setLocalPath(LOCAL_PATH);
        client.getEventManager().addCVSListener(new BasicListener());
        CheckoutCommand checkoutCmd = new CheckoutCommand();
        checkoutCmd.setBuilder(null);
        checkoutCmd.setModule("Outils");

        try {
            client.getConnection().open();
            LOG.info("CVS checkout : " + checkoutCmd.getCVSCommand());
            boolean successCheckout = client.executeCommand(checkoutCmd,globalOptions );
            LOG.info("Checkout COMPLETED : " + successCheckout);
...

调试时的输出是:

[INFO] fr.package.CvsCommandTest - CVS checkout : checkout -N Outils

cvs checkout: Updating Outils

第一行是我的日志,第二行来自监听器,但我没有得到其余的日志。 basicListener 是这样定义的:

import java.io.PrintStream;

import org.netbeans.lib.cvsclient.event.CVSAdapter;
import org.netbeans.lib.cvsclient.event.MessageEvent;

public class BasicListener extends CVSAdapter {

    /** * Stores a tagged line */
    private final StringBuffer taggedLine = new StringBuffer();

    /**
     * Called when the server wants to send a message to be displayed to the
     * user. The message is only for information purposes and clients can choose
     * to ignore these messages if they wish.
     * 
     * @param e
     *            the event
     */
    public void messageSent(MessageEvent e) {
        String line = e.getMessage();
        PrintStream stream = e.isError() ? System.err : System.out;
        if (e.isTagged()) {
            String message = MessageEvent.parseTaggedMessage(taggedLine, line);

            if (message != null) {
                stream.println(message);
            }
        } else {
            stream.println(line);
        }
        stream.close();
    }
}

我错过了什么?

已将评论转入回答

System.out stream.close(); --> 晚安...

解释:

因为他在关闭 System.out 时使用 System.out 来输出他的日志消息 @see end of public void messageSent(MessageEvent e)stream.close(); System.out已关闭,无法再使用,晚安System.out

解决方法是:

删除 stream.close(); 命令