Apache Ant Listeners and Loggers

It is a feature which allows us to monitor the progress of Ant's progress during execution. Ant uses two concepts for monitoring: listeners and loggers and both are provided by Ant itself. See the all supported listeners below.

Listeners

  1. build started
  2. build finished
  3. target started
  4. target finished
  5. task started
  6. task finished
  7. message logged

Loggers

loggers are used to extend the listeners capabilities. It has the various features, see below.

  1. It log information to the console or the file specified using -logfile parameter.
  2. It is logging level (-quite, -verbose, -debug) aware.
  3. Emacs-mode aware

Apache Ant Listeners and Loggers interface can also be represented in UML. See an UML diagram below.


Apache Ant Listeners and Loggers

It is a UML diagram of BuildListener and BuildLogger interface.

Built-in Listeners and Loggers

DataTypeParameterDescription
org.apache.tools.ant.DefaultLoggerIt is default logger and be overridden with the -logger command-line switch.BuildLogger
org.apache.tools.ant.NoBannerLoggerIt is used to omit output of empty target output.BuildLogger
org.apache.tools.ant.listener.MailLoggerIt extends DefaultLogger and generate the same output and send an email too.BuildLogger
org.apache.tools.ant.listener.AnsiColorLoggerIt is used to provide colors to the build output.BuildLogger
org.apache.tools.ant.listener.Log4jListenerIt is used to pass events to Apache Log4j logging.BuildListener
org.apache.tools.ant.XmlLoggerIt writes the build information to an XML file.BuildLogger
org.apache.tools.ant.TimestampedLoggerIt is used to print the time that a build finished.BuildLogger
org.apache.tools.ant.listener.BigProjectLoggerIt is used to print the project name every target has.BuildLogger
org.apache.tools.ant.listener.SimpleBigProjectLoggerIt prints the project name for subprojects only.BuildLogger
org.apache.tools.ant.listener.ProfileLoggerIt is a default logger with start times, end times and durations added for each task and target.BuildLogger

Any number of build listeners can be attached to a project. We can use listener while running ant from the command line by specifying listener class.

Default Logger

DefaultLogger can be run using the below command, see we have passed DefaultLogger class here.

Mail Logger

MailLogger uses DefaultLogger to capture all output logs and send success and failure message through unique email lists.

MailLogger Class Properties

PropertyDescriptionRequired
MailLogger.mailhostMail server to useNo; default localhost
MailLogger.portSMTP Port for the Mail serverNo; default 25
MailLogger.useruser name for SMTP authYes, if SMTP auth is required on your SMTP server
MailLogger.passwordpassword for SMTP authYes, if SMTP auth is required on your SMTP server
MailLogger.sslon or true if SSL is needed This feature requires JavaMailNo
MailLogger.fromMail from addressYes, if mail needs to be sent
MailLogger.replytoMail replyto address(es), comma-separatedNo
MailLogger.success.toAddress(es) to send success messages to, comma-separatedYes, if success mail is to be sent
MailLogger.success.ccAddress(es) to send success messages to carbon copy (cc), comma-separatedNo
MailLogger.success.bccAddress(es) to send success messages to blind carbon copy (bcc), comma-separatedNo

MailLogger at Command Line

ex.





Latest Courses