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 12 KiB

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