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 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Listeners &amp; Loggers</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="#AnsiColorLogger">
  58. org.apache.tools.ant.listener.AnsiColorLogger</a></code></td>
  59. <td width="33%">Colorifies the build output.</td>
  60. <td width="34%">BuildLogger</td>
  61. </tr>
  62. <tr>
  63. <td width="33%"><code><a href="#Log4jListener">
  64. org.apache.tools.ant.listener.Log4jListener</a></code></td>
  65. <td width="33%">Passes events to Log4j for highly customizable logging.</td>
  66. <td width="34%">BuildListener</td>
  67. </tr>
  68. <tr>
  69. <td width="33%"><code><a href="#XmlLogger">org.apache.tools.ant.XmlLogger</a></code></td>
  70. <td width="33%">Writes the build information to an XML file.</td>
  71. <td width="34%">BuildLogger</td>
  72. </tr>
  73. </table>
  74. <h3><a name="DefaultLogger">DefaultLogger</a></h3>
  75. <p>Simply run Ant normally, or:</p>
  76. <blockquote>
  77. <p><code>ant -logger org.apache.tools.ant.DefaultLogger</code></p>
  78. </blockquote>
  79. <h3><a name="NoBannerLogger">NoBannerLogger</a></h3>
  80. <p>Removes output of empty target output.</p>
  81. <blockquote>
  82. <p><code>ant -logger org.apache.tools.ant.NoBannerLogger</code></p>
  83. </blockquote>
  84. <h3><a name="MailLogger">MailLogger</a></h3>
  85. <p>The MailLogger captures all output logged through DefaultLogger (standard Ant
  86. output) and will send success and failure messages to unique e-mail lists, with
  87. control for turning off success or failure messages individually.</p>
  88. <p>Properties controlling the operation of MailLogger:</p>
  89. <table border="1" cellspacing="1" width="100%" id="AutoNumber2">
  90. <tr>
  91. <th width="337">Property</th>
  92. <th width="63%">Description</th>
  93. <th width="63%">Required</th>
  94. </tr>
  95. <tr>
  96. <td width="337">MailLogger.mailhost </td>
  97. <td width="63%">Mail server to use</td>
  98. <td width="63%">No, default &quot;localhost&quot;</td>
  99. </tr>
  100. <tr>
  101. <td width="337">MailLogger.port </td>
  102. <td width="63%">SMTP Port for the Mail server</td>
  103. <td width="63%">No, default &quot;25&quot;</td>
  104. </tr>
  105. <tr>
  106. <td width="337">MailLogger.user</td>
  107. <td width="63%">user name for SMTP auth</td>
  108. <td width="63%">Yes, if SMTP auth is required on your SMTP server<br/>
  109. the email message will be then sent using Mime and requires JavaMail</td>
  110. </tr>
  111. <tr>
  112. <td width="337">MailLogger.password</td>
  113. <td width="63%">password for SMTP auth</td>
  114. <td width="63%">Yes, if SMTP auth is required on your SMTP server<br/>
  115. the email message will be then sent using Mime and requires JavaMail</td>
  116. </tr>
  117. <tr>
  118. <td width="337">MailLogger.from</td>
  119. <td width="63%">Mail &quot;from&quot; address</td>
  120. <td width="63%">Yes, if mail needs to be sent</td>
  121. </tr>
  122. <tr>
  123. <td width="337">MailLogger.replyto</td>
  124. <td width="63%">Mail &quot;replyto&quot; address(es), comma-separated</td>
  125. <td width="63%">No</td>
  126. </tr>
  127. <tr>
  128. <td width="337">MailLogger.failure.notify </td>
  129. <td width="63%">Send build failure e-mails?</td>
  130. <td width="63%">No, default &quot;true&quot;</td>
  131. </tr>
  132. <tr>
  133. <td width="337">MailLogger.success.notify </td>
  134. <td width="63%">Send build success e-mails?</td>
  135. <td width="63%">No, default &quot;true&quot;</td>
  136. </tr>
  137. <tr>
  138. <td width="337">MailLogger.failure.to </td>
  139. <td width="63%">Address(es) to send failure messages to, comma-separated</td>
  140. <td width="63%">Yes, if failure mail is to be sent</td>
  141. </tr>
  142. <tr>
  143. <td width="337">MailLogger.success.to </td>
  144. <td width="63%">Address(es) to send success messages to, comma-separated</td>
  145. <td width="63%">Yes, if success mail is to be sent</td>
  146. </tr>
  147. <tr>
  148. <td width="337">MailLogger.failure.subject </td>
  149. <td width="63%">Subject of failed build</td>
  150. <td width="63%">No, default &quot;Build Failure&quot;</td>
  151. </tr>
  152. <tr>
  153. <td width="337">MailLogger.success.subject </td>
  154. <td width="63%">Subject of successful build</td>
  155. <td width="63%">No, default &quot;Build Success&quot;</td>
  156. </tr>
  157. <tr>
  158. <td width="337">MailLogger.properties.file </td>
  159. <td width="63%">Filename of properties file that will override other values.</td>
  160. <td width="63%">No</td>
  161. </tr>
  162. </table>
  163. <blockquote>
  164. <p><code>ant -logger org.apache.tools.ant.listener.MailLogger</code></p>
  165. </blockquote>
  166. <h3><a name="AnsiColorLogger">AnsiColorLogger</a></h3>
  167. <p>The AnsiColorLogger adds color to the standard Ant output
  168. by prefixing and suffixing ANSI color code escape sequences to
  169. it. It is just an extension of <a href="#DefaultLogger">DefaultLogger</a>
  170. and hence provides all features that DefaultLogger does.</p>
  171. <p>AnsiColorLogger differentiates the output by assigning
  172. different colors depending upon the type of the message.</p>
  173. <p>If used with the -logfile option, the output file
  174. will contain all the necessary escape codes to
  175. display the text in colorized mode when displayed
  176. in the console using applications like cat, more, etc.</p>
  177. <p>This is designed to work on terminals that support ANSI
  178. color codes. It works on XTerm, ETerm, Win9x Console
  179. (with ANSI.SYS loaded.), etc.</p>
  180. <p><Strong>NOTE:</Strong>
  181. It doesn't work on WinNT even when a COMMAND.COM console loaded with
  182. ANSI.SYS is used.</p>
  183. <p>If the user wishes to override the default colors
  184. with custom ones, a file containing zero or more of the
  185. custom color key-value pairs must be created. The recognized keys
  186. and their default values are shown below:</p><code><pre>
  187. AnsiColorLogger.ERROR_COLOR=2;31
  188. AnsiColorLogger.WARNING_COLOR=2;35
  189. AnsiColorLogger.INFO_COLOR=2;36
  190. AnsiColorLogger.VERBOSE_COLOR=2;32
  191. AnsiColorLogger.DEBUG_COLOR=2;34</pre></code>
  192. <p>Each key takes as value a color combination defined as
  193. <b>Attribute;Foreground;Background</b>. In the above example, background
  194. value has not been used.</p>
  195. <p>This file must be specfied as the value of a system variable
  196. named ant.logger.defaults and passed as an argument using the -D
  197. option to the <b>java</b> command that invokes the Ant application.
  198. An easy way to achieve this is to add -Dant.logger.defaults=
  199. <i>/path/to/your/file</i> to the ANT_OPTS environment variable.
  200. Ant's launching script recognizes this flag and will pass it to
  201. the java command appropriately.</p>
  202. <p>Format:</p><pre>
  203. AnsiColorLogger.*=Attribute;Foreground;Background
  204. Attribute is one of the following:
  205. 0 -&gt; Reset All Attributes (return to normal mode)
  206. 1 -&gt; Bright (Usually turns on BOLD)
  207. 2 -&gt; Dim
  208. 3 -&gt; Underline
  209. 5 -&gt; link
  210. 7 -&gt; Reverse
  211. 8 -&gt; Hidden
  212. Foreground is one of the following:
  213. 30 -&gt; Black
  214. 31 -&gt; Red
  215. 32 -&gt; Green
  216. 33 -&gt; Yellow
  217. 34 -&gt; Blue
  218. 35 -&gt; Magenta
  219. 36 -&gt; Cyan
  220. 37 -&gt; White
  221. Background is one of the following:
  222. 40 -&gt; Black
  223. 41 -&gt; Red
  224. 42 -&gt; Green
  225. 43 -&gt; Yellow
  226. 44 -&gt; Blue
  227. 45 -&gt; Magenta
  228. 46 -&gt; Cyan
  229. 47 -&gt; White</pre>
  230. <blockquote>
  231. <p><code>ant -logger org.apache.tools.ant.listener.AnsiColorLogger</code></p>
  232. </blockquote>
  233. <h3><a name="Log4jListener">Log4jListener</a></h3>
  234. <p>Passes build events to Log4j, using the full classname's of the generator of
  235. each build event as the category:</p>
  236. <ul>
  237. <li>build started / build finished - org.apache.tools.ant.Project</li>
  238. <li>target started / target finished - org.apache.tools.ant.Target</li>
  239. <li>task started / task finished - the fully qualified classname of the task</li>
  240. <li>message logged - the classname of one of the above, so if a task logs a
  241. message, its classname is the category used, and so on.</li>
  242. </ul>
  243. <p>All start events are logged as INFO.&nbsp; Finish events are either logged as
  244. INFO or ERROR depending on whether the build failed during that stage. Message
  245. events are logged according to their Ant logging level, mapping directly to a
  246. corresponding Log4j level.</p>
  247. <blockquote>
  248. <p><code>ant -listener org.apache.tools.ant.listener.Log4jListener</code></p>
  249. </blockquote>
  250. <h3><a name="XmlLogger">XmlLogger</a></h3>
  251. <p>Writes all build information out to an XML file named log.xml, or the value
  252. of the <code>XmlLogger.file</code> property if present, when used as a
  253. listener. When used as a logger, it writes all output to either the
  254. console or to the value of <code>-logfile</code>. Whether used as a listener
  255. or logger, the output is not generated until the build is complete, as it
  256. buffers the information in order to provide timing information for task,
  257. targets, and the project.
  258. <p>
  259. By default the XML file creates
  260. a reference to an XSLT file "log.xsl" in the current directory; look in
  261. ANT_HOME/etc for one of these. You can set the property
  262. <code>ant.XmlLogger.stylesheet.uri</code> to provide a uri to a style sheet.
  263. this can be a relative or absolute file path, or an http URL.
  264. If you set the property to the empty string, "", no XSLT transform
  265. is declared at all.
  266. </p>
  267. <blockquote>
  268. <p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br/>
  269. <code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p>
  270. </blockquote>
  271. <h2><a name="dev">Writing your own</a></h2>
  272. <p>See the <a href="develop.html#buildevents">Build Events</a> section for
  273. developers.</p>
  274. <p>Notes:</p>
  275. <ul>
  276. <li>A listener or logger should not write to standard output or error - Ant
  277. captures these internally and may cause an infinite loop.</li>
  278. </ul>
  279. <hr>
  280. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  281. Reserved.</p>
  282. </body>
  283. </html>