diff --git a/manual/develop.html b/manual/develop.html index ed06d3011..31add6a90 100644 --- a/manual/develop.html +++ b/manual/develop.html @@ -466,6 +466,8 @@ implementing class name to the default.properties file in the org.apache.tools.ant.taskdefs package. Then you can use it as if it were a built-in task.

+ +

Build Events

Ant is capable of generating build events as it performs the tasks necessary to build a project. @@ -522,6 +524,49 @@ been configured.

simultaneously - for example while Ant is executing a <parallel> task.

+ + + + +

Example

+Writing an adapter to your favourite log library is very easy. +Just implent the BuildListener interface, instantiate your logger and delegate +the message to that instance.
+When starting your build provide your adapter class and the log library to the +build classpath and activate your logger via -listener option as +described above. + +
+
+public class MyLogAdapter implements BuildListener {
+
+    private MyLogger getLogger() {
+        final MyLogger log = MyLoggerFactory.getLogger(Project.class.getName());
+        return log;
+    }
+
+    @Override
+    public void buildStarted(final BuildEvent event) {
+        final MyLogger log = getLogger();
+        log.info("Build started.");
+    }
+
+    @Override
+    public void buildFinished(final BuildEvent event) {
+        final MyLogger logger = getLogger();
+        MyLogLevelEnum loglevel = ... // map event.getPriority() to enum via Project.MSG_* constants
+        boolean allOK = event.getException() == null;
+        String logmessage = ... // create log message using data of the event and the message invoked
+        logger.log(loglevel, logmessage);
+    }
+
+    // implement all methods in that way
+}
+
+
+ + +

Source code integration