DocAsCodeAntLogger.java

package org.docascode.ant;

import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.fusesource.jansi.Ansi;

import java.io.PrintStream;

import static org.fusesource.jansi.Ansi.Color.*;

public class DocAsCodeAntLogger extends DefaultLogger {
    @Override
    protected void printMessage(final String message,
                                final PrintStream stream,
                                final int priority) {
        if (message != null && stream != null) {
            final Ansi.Color color;
            switch (priority) {
                case Project.MSG_ERR:
                    color = RED;
                    break;
                case Project.MSG_WARN:
                    color = YELLOW;
                    break;
                case Project.MSG_INFO:
                    color = BLUE;
                    break;
                case Project.MSG_VERBOSE:
                    color = WHITE;
                    break;
                case Project.MSG_DEBUG:
                default:
                    color = MAGENTA;
                    break;
            }
            stream.println(Ansi.ansi().fg(color).a(message).reset());
        }
    }
}