AntMessagePrinter
If you want something like logging within Ant, AntMessagePrinter is a cheap wrapper to make it happen.When you create an AntMessagePrinter object, you give it a Task or Project--at which point it pushes all logging messages through that object. The result is that you get messages that "fit" with all the other messages generated by Ant but get to use a familar Log-like API to do it.
The AntMessagePrinter uses the methods on the Task and Project to actually submit output--so it responds automatically to the command line switch you use with ant. If you use -verbose, debug() messages appear. If you use -debug, trace() messages appear.
The most common example of how to create an AntMessagePrinter would be as follows:
public class SomeTask extends Task {
protected AntMessagePrinter logger;
/**
*
*/
public SomeTask() {
super();
logger = new AntMessagePrinter();
logger.setTask(this);
}
...
}
This creates a printer and feeds it the instance. At first blush, this might seem a little more wasteful than the static class field, but Ant only keeps one instance of a Task at a time when it parses a build file--so it isn't all that bad. In addition, the AntMessagePrinter only holds references to other objects and has very little memory footprint per instance.
See the API
for more information.
/rsh tech

