If I execute a build command, I would like to suppress unnecessary output. I only want to see errors and warnings. When I do "ant -quiet -emacs >2 /dev/null" I can suppress nearly all non-error, non-warning output, but I still get messages like: BUILD SUCCESSFUL Total time: 11 seconds Which I think should be suppressed as part of "-quiet".
No much changes in Ant that breaks backward compatibility / behavior... Sounds like you want a new -readquiet or -silent switch that also suppresses the 'BUILD SUCCESSFUL / FAILED' & 'Total time' lines. Of course, you'd get a better chance to have it appear in Ant if you provide a patch for it ;-) --DD
Changing the "buildFinished" method in "org.apache.tools.ant.DefaultLogger" to the following fixes the issue. If msgOutputLevel is "error" or "warning" (i.e., as with -quiet), the message is suppressed. Otherwise, it will be printed normally. public void buildFinished(BuildEvent event) { Throwable error = event.getException(); StringBuffer message = new StringBuffer(); if (error == null) { if (msgOutputLevel > Project.MSG_WARN) { message.append(StringUtils.LINE_SEP); message.append("BUILD SUCCESSFUL"); } } else { message.append(StringUtils.LINE_SEP); message.append("BUILD FAILED"); message.append(StringUtils.LINE_SEP); if (Project.MSG_VERBOSE <= msgOutputLevel || !(error instanceof BuildException)) { message.append(StringUtils.getStackTrace(error)); } else { if (error instanceof BuildException) { message.append(error.toString()).append(lSep); } else { message.append(error.getMessage()).append(lSep); } } } if (msgOutputLevel > Project.MSG_WARN) { message.append(StringUtils.LINE_SEP); message.append("Total time: "); message.append(formatTime(System.currentTimeMillis() - startTime)); } String msg = message.toString(); if (error == null) { if (msg.length() > 0) { printMessage(msg, out, Project.MSG_VERBOSE); } } else { printMessage(msg, err, Project.MSG_ERR); } log(msg); }
Why not just create your own logger?
You could create your own logger, but it just seems like it you specify "- quiet", the correct behavior should be to suppress unnecessary messages. Another possibility would be to have ant send errors and warnings to System.err rather than System.out. That way I could just say "ant -emacs 1> /dev/null" and only the errors and warnings would go to the console.
I second this request - I'm calling ant from as a cronjob on sourceforge and get an email if anything is printed to stdout. By specifying -quiet (or possibly a new -veryquiet) I'd expect ant to not report the 'information'-level message: BUILD SUCCESSFUL Total time: 34 seconds Supressing this message should be supported (it's a trivial fix as posted in another comment) so not everyone automating with ant has to write his/her own logger. Thanks
Created attachment 25511 [details] Adds a new argument -veryquiet which suppresses "Build Successful" message and outputs nothing on no errors and warnings. I know this is an old bug, and nobody wanted to change existing functionality. But it was trivial and just waiting to be done, so I did it. The patch I'm submitting takes a new "-veryquiet" argument which suppresses all messages if there are no errors or warnings.
I would agree that the existing -quiet argument ought to be fixed, rather than introducing a new option.
I was going to do the same thing, but thought that preserving backward behavior is a better idea. Here's what I'll do: I'm going to submit a new patch, and let the core members decide. Given that this design decision has not been resolved in 8 years though, I don't think that this'll be resolved soon.