I have an ant buildfile that is often run from vastly different environments. By default, I\'m looking for the same behavior as using:
ant -q
For controlling the loglevel from within your ant script you could take this simple task =
public class SetLogLevel extends Task
{
private int logLevel = -1;
public void execute()
{
if (logLevel == -1)
{
throw new BuildException("Error - No Loglevel specified !!");
}
Vector listeners = this.getProject().getBuildListeners();
for (Iterator i = listeners.iterator(); i.hasNext();)
{
BuildListener listener = (BuildListener) i.next();
if (listener instanceof BuildLogger)
{
BuildLogger logger = (BuildLogger) listener;
logger.setMessageOutputLevel(logLevel);
}
}
}
/**
*
* @see org.apache.tools.ant.taskdefs.Echo$EchoLevel
*
*/
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;
}
}
}
map it to a taskdef and use it like that =
... only errors should be listed
... loglevel info again
That's what i do to shorten logfiles when using talkative tasks like f.e. cvs task