package org.elasticsearch.junit.listerners;

import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder;
import com.carrotsearch.randomizedtesting.TraceFormatting;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

/**
 * A {@link RunListener} that emits to {@link System#err} a string with command
 * line parameters allowing quick test re-run under ANT command line.
 */
public class ReproduceInfoPrinter extends RunListener {

    
    @Override
    public void testFailure(Failure failure) throws Exception {
        // Ignore assumptions.
        if (failure.getException() instanceof AssumptionViolatedException) {
            return;
        }

        final Description d = failure.getDescription();
        final StringBuilder b = new StringBuilder();
        b.append("FAILURE  : ").append(d.getDisplayName()).append("\n");
        b.append("REPRODUCE WITH  : mvn test");
        new MavenMessageBuilder(b).appendAllOpts(failure.getDescription());

        b.append("\n");
        b.append("Throwable:\n");
        if (failure.getException() != null) {
            TraceFormatting traces = new TraceFormatting();
            try {
                traces = RandomizedContext.current().getRunner().getTraceFormatting();
            } catch (IllegalStateException e) {
                // Ignore if no context.
            }
            traces.formatThrowable(b, failure.getException());
        }
        System.out.println(b.toString());
    }

    private static class MavenMessageBuilder extends ReproduceErrorMessageBuilder {

        public MavenMessageBuilder(StringBuilder b) {
            super(b);
        }

        /**
         * Append a single VM option.
         */
        public ReproduceErrorMessageBuilder appendOpt(String sysPropName, String value) {
            if (sysPropName.equals("tests.iters")) { // we don't want the iters to be in there!
                return this;
            }
            return super.appendOpt(sysPropName, value);
        }
    }
}

@@ -230,16 +230,180 @@
 atting;%0A
+import org.elasticsearch.common.logging.ESLogger;%0Aimport org.elasticsearch.common.logging.Loggers;%0Aimport org.elasticsearch.test.integration.ElasticsearchTestCase;%0A
 import o
@@ -802,16 +802,261 @@
  %7B%0A%0A    
+protected final ESLogger logger = Loggers.getLogger(ElasticsearchTestCase.class);%0A%0A    @Override%0A    public void testStarted(Description description) throws Exception %7B%0A        logger.info(%22Test %7B%7D started%22, description.getDisplayName());%0A    %7D%0A
 %0A    @Ov
@@ -2029,26 +2029,20 @@
     
-System.out.println
+logger.error
 (b.t

Add test method information to log output