📜  Apache Ant侦听器和记录器

📅  最后修改于: 2020-12-26 13:39:49             🧑  作者: Mango

Apache Ant侦听器和记录器

它是一项功能,使我们可以在执行期间监视Ant的进度。 Ant使用两个概念进行监视:侦听器和记录器,两者均由Ant本身提供。请参阅下面所有受支持的侦听器。

听众

  • 建立开始
  • 构建完成
  • 目标已开始
  • 目标完成
  • 任务开始
  • 任务完成
  • 消息已记录

记录仪

记录器用于扩展侦听器功能。它具有各种功能,请参见下文。

  • 它将信息记录到控制台或使用-logfile参数指定的文件中。
  • 它对日志记录级别(-相当,-详细,-调试)知道。
  • Emacs模式感知

Apache Ant侦听器和记录器接口也可以用UML表示。请参阅下面的UML图。

它是BuildListener和BuildLogger接口的UML图。

内置的侦听器和记录器

DataType Parameter Description
org.apache.tools.ant.DefaultLogger It is default logger and be overridden with the -logger command-line switch. BuildLogger
org.apache.tools.ant.NoBannerLogger It is used to omit output of empty target output. BuildLogger
org.apache.tools.ant.listener.MailLogger It extends DefaultLogger and generate the same output and send an email too. BuildLogger
org.apache.tools.ant.listener.AnsiColorLogger It is used to provide colors to the build output. BuildLogger
org.apache.tools.ant.listener.Log4jListener It is used to pass events to Apache Log4j logging. BuildListener
org.apache.tools.ant.XmlLogger It writes the build information to an XML file. BuildLogger
org.apache.tools.ant.TimestampedLogger It is used to print the time that a build finished. BuildLogger
org.apache.tools.ant.listener.BigProjectLogger It is used to print the project name every target has. BuildLogger
org.apache.tools.ant.listener.SimpleBigProjectLogger It prints the project name for subprojects only. BuildLogger
org.apache.tools.ant.listener.ProfileLogger It is a default logger with start times, end times and durations added for each task and target. BuildLogger

可以将任何数量的构建侦听器附加到项目。通过指定侦听器类,我们可以在从命令行运行ant时使用侦听器。

默认记录器

可以使用以下命令运行DefaultLogger,请参阅此处传递的DefaultLogger类。

$ ant -logger org.apache.tools.ant.DefaultLogger

邮件记录仪

MailLogger使用DefaultLogger捕获所有输出日志,并通过唯一的电子邮件列表发送成功和失败消息。

MailLogger类属性

Property Description Required
MailLogger.mailhost Mail server to use No; default localhost
MailLogger.port SMTP Port for the Mail server No; default 25
MailLogger.user user name for SMTP auth Yes, if SMTP auth is required on your SMTP server
MailLogger.password password for SMTP auth Yes, if SMTP auth is required on your SMTP server
MailLogger.ssl on or true if SSL is needed This feature requires JavaMail No
MailLogger.from Mail from address Yes, if mail needs to be sent
MailLogger.replyto Mail replyto address(es), comma-separated No
MailLogger.success.to Address(es) to send success messages to, comma-separated Yes, if success mail is to be sent
MailLogger.success.cc Address(es) to send success messages to carbon copy (cc), comma-separated No
MailLogger.success.bcc Address(es) to send success messages to blind carbon copy (bcc), comma-separated No

命令行中的MailLogger

例如

ant -logger org.apache.tools.ant.listener.MailLogger