Browse Source

Now writes message to the logger, rather than to System.out.

Also introduced logging levels to provide finer control over
when messages are writen out.  The levels simply reflect the
current Project.MSG_* values.

Suggested by:           Wolf Siberski


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268204 13f79535-47bb-0310-9956-ffa450edef68
master
glennm 24 years ago
parent
commit
0b48664390
1 changed files with 43 additions and 5 deletions
  1. +43
    -5
      src/main/org/apache/tools/ant/taskdefs/Echo.java

+ 43
- 5
src/main/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.types.EnumeratedAttribute;
import java.io.*;
/**
* Echo
@@ -62,9 +63,12 @@ import java.io.*;
* @author costin@dnt.ro
*/
public class Echo extends Task {
private String message = ""; // required
private File file = null;
private boolean append = false;
protected String message = ""; // required
protected File file = null;
protected boolean append = false;
// by default, messages are always displayed
protected int logLevel = Project.MSG_WARN;
/**
* Does the work.
@@ -73,7 +77,7 @@ public class Echo extends Task {
*/
public void execute() throws BuildException {
if (file == null) {
System.out.println(message);
log(message, logLevel);
} else {
FileWriter out = null;
try {
@@ -97,7 +101,7 @@ public class Echo extends Task {
* @param msg Sets the value for the message variable.
*/
public void setMessage(String msg) {
this.message = msg;
this.message = msg;
}

/**
@@ -121,4 +125,38 @@ public class Echo extends Task {
message +=
ProjectHelper.replaceProperties(msg, project.getProperties());
}

/**
* Set the logging level to one of
* <ul>
* <li>error</li>
* <li>warning</li>
* <li>info</li>
* <li>verbose</li>
* <li>debug</li>
* <ul>
* <p>The default is &quot;warning&quot; to ensure that messages are
* displayed by default when using the -quiet command line option.</p>
*/
public void setLevel(EchoLevel echoLevel) {
String option = echoLevel.getValue();
if (option.equals("error")) {
logLevel = Project.MSG_ERR;
} else if (option.equals("warning")) {
logLevel = Project.MSG_WARN;
} else if (option.equals("info")) {
logLevel = Project.MSG_INFO;
} else if (option.equals("verbose")) {
logLevel = Project.MSG_VERBOSE;
} else {
// must be "debug"
logLevel = Project.MSG_DEBUG;
}
}

public static class EchoLevel extends EnumeratedAttribute {
public String[] getValues() {
return new String[] {"error", "warning", "info", "verbose", "debug"};
}
}
}

Loading…
Cancel
Save