You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

listeners.html 6.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h1>Listeners &amp; Loggers</h1>
  8. <h2><a name="Overview">Overview</a></h2>
  9. <p>Ant has two related features to allow the build process to be monitored:
  10. listeners and loggers.</p>
  11. <h3><a name="Listeners">Listeners</a></h3>
  12. <p>A listener is alerted of the following events:</p>
  13. <ul>
  14. <li>build started</li>
  15. <li>build finished</li>
  16. <li>target started</li>
  17. <li>target finished</li>
  18. <li>task started</li>
  19. <li>task finished</li>
  20. <li>message logged</li>
  21. </ul>
  22. <h3><a name="Loggers">Loggers</a></h3>
  23. <p>Loggers extend the capabilities of listeners and add the following features:</p>
  24. <ul>
  25. <li>Receives a handle to the standard output and error print streams and
  26. therefore can log information to the console or the -logfile specified file.</li>
  27. <li>Logging level (-quiet, -verbose, -debug) aware</li>
  28. <li>Emacs-mode aware</li>
  29. </ul>
  30. <h2><a name="builtin">Built-in Listeners/Loggers</a></h2>
  31. <table border="1" cellspacing="1" width="100%" id="AutoNumber1">
  32. <tr>
  33. <td width="33%">Classname</td>
  34. <td width="33%">Description</td>
  35. <td width="34%">Type</td>
  36. </tr>
  37. <tr>
  38. <td width="33%"><code><a href="#DefaultLogger">org.apache.tools.ant.DefaultLogger</a></code></td>
  39. <td width="33%">The logger used implicitly unless overridden with the
  40. <code>-logger</code> command-line switch.</td>
  41. <td width="34%">BuildLogger</td>
  42. </tr>
  43. <tr>
  44. <td width="33%"><code><a href="#NoBannerLogger">
  45. org.apache.tools.ant.NoBannerLogger</a></code></td>
  46. <td width="33%">This logger omits output of empty target output.</td>
  47. <td width="34%">BuildLogger</td>
  48. </tr>
  49. <tr>
  50. <td width="33%"><code><a href="#MailLogger">
  51. org.apache.tools.ant.listener.MailLogger</a></code></td>
  52. <td width="33%">Extends DefaultLogger such that output is still generated
  53. the same, and when the build is finished an e-mail can be sent.</td>
  54. <td width="34%">BuildLogger</td>
  55. </tr>
  56. <tr>
  57. <td width="33%"><code><a href="#Log4jListener">
  58. org.apache.tools.ant.listener.Log4jListener</a></code></td>
  59. <td width="33%">Passes events to Log4j for highly customizable logging.</td>
  60. <td width="34%">BuildListener</td>
  61. </tr>
  62. <tr>
  63. <td width="33%"><code><a href="#XmlLogger">org.apache.tools.ant.XmlLogger</a></code></td>
  64. <td width="33%">Writes the build information to an XML file.</td>
  65. <td width="34%">BuildListener</td>
  66. </tr>
  67. </table>
  68. <h3><a name="DefaultLogger">DefaultLogger</a></h3>
  69. <p>Simply run Ant normally, or:</p>
  70. <blockquote>
  71. <p><code>ant -logger org.apache.tools.ant.DefaultLogger</code></p>
  72. </blockquote>
  73. <h3><a name="NoBannerLogger">NoBannerLogger</a></h3>
  74. <p>Removes output of empty target output.</p>
  75. <blockquote>
  76. <p><code>ant -logger org.apache.tools.ant.NoBannerLogger</code></p>
  77. </blockquote>
  78. <h3><a name="MailLogger">MailLogger</a></h3>
  79. <p>The MailLogger captures all output logged through DefaultLogger (standard Ant
  80. output) and will send success and failure messages to unique e-mail lists, with
  81. control for turning off success or failure messages individually.</p>
  82. <p>Properties controlling the operation of MailLogger:</p>
  83. <table border="1" cellspacing="1" width="100%" id="AutoNumber2">
  84. <tr>
  85. <th width="337">Property</th>
  86. <th width="63%">Description</th>
  87. <th width="63%">Required</th>
  88. </tr>
  89. <tr>
  90. <td width="337">MailLogger.mailhost </td>
  91. <td width="63%">Mail server to use</td>
  92. <td width="63%">No, default &quot;localhost&quot;</td>
  93. </tr>
  94. <tr>
  95. <td width="337">MailLogger.from</td>
  96. <td width="63%">Mail &quot;from&quot; address</td>
  97. <td width="63%">Yes, if mail needs to be sent</td>
  98. </tr>
  99. <tr>
  100. <td width="337">MailLogger.failure.notify </td>
  101. <td width="63%">Send build failure e-mails?</td>
  102. <td width="63%">No, default &quot;true&quot;</td>
  103. </tr>
  104. <tr>
  105. <td width="337">MailLogger.success.notify </td>
  106. <td width="63%">Send build success e-mails?</td>
  107. <td width="63%">No, default &quot;true&quot;</td>
  108. </tr>
  109. <tr>
  110. <td width="337">MailLogger.failure.to </td>
  111. <td width="63%">Address(es) to send failure messages to, comma-separated</td>
  112. <td width="63%">Yes, if failure mail is to be sent</td>
  113. </tr>
  114. <tr>
  115. <td width="337">MailLogger.success.to </td>
  116. <td width="63%">Address(es) to send success messages to, comma-separated</td>
  117. <td width="63%">Yes, if success mail is to be sent</td>
  118. </tr>
  119. <tr>
  120. <td width="337">MailLogger.failure.subject </td>
  121. <td width="63%">Subject of failed build</td>
  122. <td width="63%">No, default &quot;Build Failure&quot;</td>
  123. </tr>
  124. <tr>
  125. <td width="337">MailLogger.success.subject </td>
  126. <td width="63%">Subject of successful build</td>
  127. <td width="63%">No, default &quot;Build Success&quot;</td>
  128. </tr>
  129. <tr>
  130. <td width="337">MailLogger.properties.file </td>
  131. <td width="63%">Filename of properties file that will override other values.</td>
  132. <td width="63%">No</td>
  133. </tr>
  134. </table>
  135. <blockquote>
  136. <p><code>ant -logger org.apache.tools.ant.listener.MailLogger</code></p>
  137. </blockquote>
  138. <h3><a name="Log4jListener">Log4jListener</a></h3>
  139. <p>Passes build events to Log4j, using the full classname's of the generator of
  140. each build event as the category:</p>
  141. <ul>
  142. <li>build started / build finished - org.apache.tools.ant.Project</li>
  143. <li>target started / target finished - org.apache.tools.ant.Target</li>
  144. <li>task started / task finished - the fully qualified classname of the task</li>
  145. <li>message logged - the classname of one of the above, so if a task logs a
  146. message, its classname is the category used, and so on.</li>
  147. </ul>
  148. <p>All start events are logged as INFO.&nbsp; Finish events are either logged as
  149. INFO or ERROR depending on whether the build failed during that stage. Message
  150. events are logged according to their Ant logging level, mapping directly to a
  151. corresponding Log4j level.</p>
  152. <blockquote>
  153. <p><code>ant -listener org.apache.tools.ant.listener.Log4jListener</code></p>
  154. </blockquote>
  155. <h3><a name="XmlLogger">XmlLogger</a></h3>
  156. <p>Writes all build information out to an XML file named log.xml, or the value
  157. of the XmlLogger.file property if present.</p>
  158. <blockquote>
  159. <p><code>ant -listener org.apache.tools.ant.XmlLogger</code></p>
  160. </blockquote>
  161. <h2><a name="dev">Writing your own</a></h2>
  162. <p>See the <a href="develop.html#buildevents">Build Events</a> section for
  163. developers.</p>
  164. <p>Notes:</p>
  165. <ul>
  166. <li>A listener or logger should not write to standard output or error - Ant
  167. captures these internally and may cause an infinite loop.</li>
  168. </ul>
  169. <hr>
  170. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  171. Reserved.</p>
  172. </body>
  173. </html>