Ant - Listeners & Loggers

Ant allows the build process to be monitored using listeners and loggers.


Ant provides following events to be captured using listeners.

  • build started

  • build finished

  • target started

  • target finished

  • task started

  • task finished

  • message logged

Custom listeners can be registered on command line using -listener argument.


Loggers extends listeners capabilities and add the following features

  • Can log information to console or file using -logfile argument

  • Can log using logging levels like -quiet, -verbose, -debug

  • Are emacs-mode aware

Built-in Listeners/loggers

  • − The logger used implicitly unless overridden with the -logger command-line switch.

  • − This logger omits output of empty target output.

  • − Extends DefaultLogger such that output is still generated the same, and when the build is finished an e-mail can be sent.

  • − Colorifies the build output.

  • − Passes events to Apache Log4j for highly customizable logging.

  • − Writes the build information to an XML file.

  • − Prints the time that a build finished

  • − Prints the project name every target

  • − Prints the project name for subprojects only, otherwise like NoBannerLogger Since Ant 1.8.1

  • − The default logger, with start times, end times and durations added for each task and target.


Create build.xml with the following content:

<?xml version="1.0"?>
<project name="sample" basedir="." default="copy">
   <target name="copy">
     <echo>File Copied</echo>


Running Ant on the above build file produces the following output −

F:\tutorialspoint\ant>ant -logger
Buildfile: F:\tutorialspoint\ant\build.xml

   [echo] File Copied

BUILD SUCCESSFUL - at 03/12/21, 11:24 AM
Total time: 0 seconds

F:\tutorialspoint\ant>ant -logger -verbose -logfile build_log.xml
Apache Ant(TM) version 1.10.12 compiled on October 13 2021
Trying the default build file: build.xml
Buildfile: F:\tutorialspoint\ant\build.xml

Now you can check build_log.xml file is created with relevant logs.