You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/09/06 13:34:43 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java
bodewig 00/09/06 04:34:42
Modified: src/main/org/apache/tools/ant BuildLogger.java
DefaultLogger.java Main.java
src/main/org/apache/tools/ant/taskdefs Ant.java
Log:
If the output has not been redirected (via -logfile) write error
messages to stderr instead of stdout.
Suggested by: Peter Nordlund <pe...@lentus.se>
Revision Changes Path
1.2 +9 -1 jakarta-ant/src/main/org/apache/tools/ant/BuildLogger.java
Index: BuildLogger.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/BuildLogger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BuildLogger.java 2000/07/25 13:15:29 1.1
+++ BuildLogger.java 2000/09/06 11:34:37 1.2
@@ -89,4 +89,12 @@
* editors can parse files names, etc.
*/
public void setEmacsMode(boolean emacsMode);
-}
\ No newline at end of file
+
+ /**
+ * 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);
+
+}
1.7 +19 -7 jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java
Index: DefaultLogger.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultLogger.java 2000/09/04 14:21:56 1.6
+++ DefaultLogger.java 2000/09/06 11:34:38 1.7
@@ -65,6 +65,7 @@
private static int LEFT_COLUMN_SIZE = 12;
private PrintStream out;
+ private PrintStream err;
private int msgOutputLevel;
private long startTime = System.currentTimeMillis();
@@ -95,6 +96,15 @@
}
/**
+ * 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.
*
* @param emacsMode true if output is to be unadorned so that emacs and other
@@ -120,18 +130,18 @@
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 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 @@
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());
}
}
1.18 +5 -0 jakarta-ant/src/main/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Main.java 2000/08/27 14:11:24 1.17
+++ Main.java 2000/09/06 11:34:38 1.18
@@ -81,6 +81,9 @@
/** 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 @@
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 @@
logger.setMessageOutputLevel(msgOutputLevel);
logger.setOutputPrintStream(out);
+ logger.setErrorPrintStream(err);
logger.setEmacsMode(emacsMode);
return logger;
1.15 +1 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
Index: Ant.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Ant.java 2000/08/04 13:30:55 1.14
+++ Ant.java 2000/09/06 11:34:41 1.15
@@ -123,6 +123,7 @@
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(out);
+ logger.setErrorPrintStream(out);
p1.addBuildListener(logger);
}
catch( IOException ex ) {