Browse Source

If the output has not been redirected (via -logfile) write error

messages to stderr instead of stdout.
Suggested by:	Peter Nordlund <peter.nordlund@lentus.se>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267968 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
8b2d7026b2
4 changed files with 34 additions and 8 deletions
  1. +9
    -1
      src/main/org/apache/tools/ant/BuildLogger.java
  2. +19
    -7
      src/main/org/apache/tools/ant/DefaultLogger.java
  3. +5
    -0
      src/main/org/apache/tools/ant/Main.java
  4. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/Ant.java

+ 9
- 1
src/main/org/apache/tools/ant/BuildLogger.java View File

@@ -89,4 +89,12 @@ public interface BuildLogger extends BuildListener {
* editors can parse files names, etc.
*/
public void setEmacsMode(boolean emacsMode);
}

/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
public void setErrorPrintStream(PrintStream err);
}

+ 19
- 7
src/main/org/apache/tools/ant/DefaultLogger.java View File

@@ -65,6 +65,7 @@ public class DefaultLogger implements BuildLogger {
private static int LEFT_COLUMN_SIZE = 12;

private PrintStream out;
private PrintStream err;
private int msgOutputLevel;
private long startTime = System.currentTimeMillis();
@@ -94,6 +95,15 @@ public class DefaultLogger implements BuildLogger {
this.out = output;
}

/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
public void setErrorPrintStream(PrintStream err) {
this.err = err;
}

/**
* Set this logger to produce emacs (and other editor) friendly output.
*
@@ -120,18 +130,18 @@ public class DefaultLogger implements BuildLogger {
out.println(lSep + "BUILD SUCCESSFUL");
}
else {
out.println(lSep + "BUILD FAILED" + lSep);
err.println(lSep + "BUILD FAILED" + lSep);

if (error instanceof BuildException) {
out.println(error.toString());
err.println(error.toString());

Throwable nested = ((BuildException)error).getException();
if (nested != null) {
nested.printStackTrace(out);
nested.printStackTrace(err);
}
}
else {
error.printStackTrace(out);
error.printStackTrace(err);
}
}

@@ -152,6 +162,8 @@ public class DefaultLogger implements BuildLogger {

public void messageLogged(BuildEvent event) {

PrintStream logTo = event.getPriority() == Project.MSG_ERR ? err : out;

// Filter out messages based on priority
if (event.getPriority() <= msgOutputLevel) {

@@ -162,14 +174,14 @@ public class DefaultLogger implements BuildLogger {
if (!emacsMode) {
String msg = "[" + name + "] ";
for (int i = 0; i < (LEFT_COLUMN_SIZE - msg.length()); i++) {
out.print(" ");
logTo.print(" ");
}
out.print(msg);
logTo.print(msg);
}
}

// Print the message
out.println(event.getMessage());
logTo.println(event.getMessage());
}
}



+ 5
- 0
src/main/org/apache/tools/ant/Main.java View File

@@ -81,6 +81,9 @@ public class Main {
/** Stream that we are using for logging */
private PrintStream out = System.out;

/** Stream that we are using for logging error messages */
private PrintStream err = System.err;

/** The build targets */
private Vector targets = new Vector(5);

@@ -152,6 +155,7 @@ public class Main {
File logFile = new File(args[i+1]);
i++;
out = new PrintStream(new FileOutputStream(logFile));
err = out;
System.setOut(out);
System.setErr(out);
} catch (IOException ioe) {
@@ -367,6 +371,7 @@ public class Main {
logger.setMessageOutputLevel(msgOutputLevel);
logger.setOutputPrintStream(out);
logger.setErrorPrintStream(err);
logger.setEmacsMode(emacsMode);
return logger;


+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -123,6 +123,7 @@ public class Ant extends Task {
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(out);
logger.setErrorPrintStream(out);
p1.addBuildListener(logger);
}
catch( IOException ex ) {


Loading…
Cancel
Save