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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  19. <title>Listeners &amp; Loggers</title>
  20. </head>
  21. <body>
  22. <h1>Listeners &amp; Loggers</h1>
  23. <h2><a name="Overview">Overview</a></h2>
  24. <p>Apache Ant has two related features to allow the build process to be monitored:
  25. listeners and loggers.</p>
  26. <h3><a name="Listeners">Listeners</a></h3>
  27. <p>A listener is alerted of the following events:</p>
  28. <ul>
  29. <li>build started</li>
  30. <li>build finished</li>
  31. <li>target started</li>
  32. <li>target finished</li>
  33. <li>task started</li>
  34. <li>task finished</li>
  35. <li>message logged</li>
  36. </ul>
  37. <p>
  38. These are used internally for various recording and housekeeping operations,
  39. however new listeners may registered on the command line through the <code>-listener</code>
  40. argument.
  41. </p>
  42. <h3><a name="Loggers">Loggers</a></h3>
  43. <p>Loggers extend the capabilities of listeners and add the following features:</p>
  44. <ul>
  45. <li>Receives a handle to the standard output and error print streams and
  46. therefore can log information to the console or the <code>-logfile</code> specified file.</li>
  47. <li>Logging level (-quiet, -verbose, -debug) aware</li>
  48. <li>Emacs-mode aware</li>
  49. </ul>
  50. <h2><a name="builtin">Built-in Listeners/Loggers</a></h2>
  51. <table border="1" cellspacing="1" width="100%" id="AutoNumber1">
  52. <tr>
  53. <td width="33%">Classname</td>
  54. <td width="33%">Description</td>
  55. <td width="34%">Type</td>
  56. </tr>
  57. <tr>
  58. <td width="33%"><code><a href="#DefaultLogger">org.apache.tools.ant.DefaultLogger</a></code></td>
  59. <td width="33%">The logger used implicitly unless overridden with the
  60. <code>-logger</code> command-line switch.</td>
  61. <td width="34%">BuildLogger</td>
  62. </tr>
  63. <tr>
  64. <td width="33%"><code><a href="#NoBannerLogger">
  65. org.apache.tools.ant.NoBannerLogger</a></code></td>
  66. <td width="33%">This logger omits output of empty target output.</td>
  67. <td width="34%">BuildLogger</td>
  68. </tr>
  69. <tr>
  70. <td width="33%"><code><a href="#MailLogger">
  71. org.apache.tools.ant.listener.MailLogger</a></code></td>
  72. <td width="33%">Extends DefaultLogger such that output is still generated
  73. the same, and when the build is finished an e-mail can be sent.</td>
  74. <td width="34%">BuildLogger</td>
  75. </tr>
  76. <tr>
  77. <td width="33%"><code><a href="#AnsiColorLogger">
  78. org.apache.tools.ant.listener.AnsiColorLogger</a></code></td>
  79. <td width="33%">Colorifies the build output.</td>
  80. <td width="34%">BuildLogger</td>
  81. </tr>
  82. <tr>
  83. <td width="33%"><code><a href="#Log4jListener">
  84. org.apache.tools.ant.listener.Log4jListener</a></code></td>
  85. <td width="33%">
  86. Passes events to Apache Log4j for highly customizable logging.<br>
  87. <b>Deprecated:</b> Apache Log4j (1.x) is not developed any more. Last
  88. release is 1.2.17 from 26-May-2012 and contains vulnerability issues.
  89. </td>
  90. <td width="34%">BuildListener</td>
  91. </tr>
  92. <tr>
  93. <td width="33%"><code><a href="#XmlLogger">org.apache.tools.ant.XmlLogger</a></code></td>
  94. <td width="33%">Writes the build information to an XML file.</td>
  95. <td width="34%">BuildLogger</td>
  96. </tr>
  97. <tr>
  98. <td width="33%"><code><a href="#TimestampedLogger">org.apache.tools.ant.TimestampedLogger</a></code></td>
  99. <td width="33%">Prints the time that a build finished</td>
  100. <td width="34%">BuildLogger</td>
  101. </tr>
  102. <tr>
  103. <td width="33%"><code><a href="#BigProjectLogger">org.apache.tools.ant.listener.BigProjectLogger</a></code></td>
  104. <td width="33%">Prints the project name every target</td>
  105. <td width="34%">BuildLogger</td>
  106. </tr>
  107. <tr>
  108. <td width="33%"><code><a href="#SimpleBigProjectLogger">org.apache.tools.ant.listener.SimpleBigProjectLogger</a></code></td>
  109. <td width="33%">Prints the project name for subprojects only, otherwise like NoBannerLogger <em>Since Ant 1.8.1</em></td>
  110. <td width="34%">BuildLogger</td>
  111. </tr>
  112. <tr>
  113. <td width="33%"><code><a href="#ProfileLogger">org.apache.tools.ant.listener.ProfileLogger</a></code></td>
  114. <td width="33%">The default logger, with start times, end times and
  115. durations added for each task and target.</td>
  116. <td width="34%">BuildLogger</td>
  117. </tr>
  118. </table>
  119. <h3><a name="DefaultLogger">DefaultLogger</a></h3>
  120. <p>Simply run Ant normally, or:</p>
  121. <blockquote>
  122. <p><code>ant -logger org.apache.tools.ant.DefaultLogger</code></p>
  123. </blockquote>
  124. <h3><a name="NoBannerLogger">NoBannerLogger</a></h3>
  125. <p>Removes output of empty target output.</p>
  126. <blockquote>
  127. <p><code>ant -logger org.apache.tools.ant.NoBannerLogger</code></p>
  128. </blockquote>
  129. <h3><a name="MailLogger">MailLogger</a></h3>
  130. <p>The MailLogger captures all output logged through DefaultLogger (standard Ant
  131. output) and will send success and failure messages to unique e-mail lists, with
  132. control for turning off success or failure messages individually.</p>
  133. <p>Properties controlling the operation of MailLogger:</p>
  134. <table border="1" cellspacing="1" width="100%" id="AutoNumber2">
  135. <tr>
  136. <th width="337">Property</th>
  137. <th width="63%">Description</th>
  138. <th width="63%">Required</th>
  139. </tr>
  140. <tr>
  141. <td width="337">MailLogger.mailhost </td>
  142. <td width="63%">Mail server to use</td>
  143. <td width="63%">No, default &quot;localhost&quot;</td>
  144. </tr>
  145. <tr>
  146. <td width="337">MailLogger.port </td>
  147. <td width="63%">SMTP Port for the Mail server</td>
  148. <td width="63%">No, default &quot;25&quot;</td>
  149. </tr>
  150. <tr>
  151. <td width="337">MailLogger.user</td>
  152. <td width="63%">user name for SMTP auth</td>
  153. <td width="63%">Yes, if SMTP auth is required on your SMTP server<br>
  154. the email message will be then sent using Mime and requires JavaMail</td>
  155. </tr>
  156. <tr>
  157. <td width="337">MailLogger.password</td>
  158. <td width="63%">password for SMTP auth</td>
  159. <td width="63%">Yes, if SMTP auth is required on your SMTP server<br>
  160. the email message will be then sent using Mime and requires JavaMail</td>
  161. </tr>
  162. <tr>
  163. <td width="337">MailLogger.ssl</td>
  164. <td width="63%">on or true if ssl is needed<br>
  165. This feature requires JavaMail</td>
  166. <td width="63%">
  167. no</td>
  168. </tr>
  169. <tr>
  170. <td width="337">MailLogger.from</td>
  171. <td width="63%">Mail &quot;from&quot; address</td>
  172. <td width="63%">Yes, if mail needs to be sent</td>
  173. </tr>
  174. <tr>
  175. <td width="337">MailLogger.replyto</td>
  176. <td width="63%">Mail &quot;replyto&quot; address(es), comma-separated</td>
  177. <td width="63%">No</td>
  178. </tr>
  179. <tr>
  180. <td width="337">MailLogger.failure.notify </td>
  181. <td width="63%">Send build failure e-mails?</td>
  182. <td width="63%">No, default &quot;true&quot;</td>
  183. </tr>
  184. <tr>
  185. <td width="337">MailLogger.success.notify </td>
  186. <td width="63%">Send build success e-mails?</td>
  187. <td width="63%">No, default &quot;true&quot;</td>
  188. </tr>
  189. <tr>
  190. <td width="337">MailLogger.failure.to </td>
  191. <td width="63%">Address(es) to send failure messages to, comma-separated</td>
  192. <td width="63%">Yes, if failure mail is to be sent</td>
  193. </tr>
  194. <tr>
  195. <td width="337">MailLogger.success.to </td>
  196. <td width="63%">Address(es) to send success messages to, comma-separated</td>
  197. <td width="63%">Yes, if success mail is to be sent</td>
  198. </tr>
  199. <tr>
  200. <td width="337">MailLogger.failure.cc </td>
  201. <td width="63%">Address(es) to send failure messages to carbon copy (cc), comma-separated</td>
  202. <td width="63%">No</td>
  203. </tr>
  204. <tr>
  205. <td width="337">MailLogger.success.cc </td>
  206. <td width="63%">Address(es) to send success messages to carbon copy (cc), comma-separated</td>
  207. <td width="63%">No</td>
  208. </tr>
  209. <tr>
  210. <td width="337">MailLogger.failure.bcc </td>
  211. <td width="63%">Address(es) to send failure messages to blind carbon copy (bcc), comma-separated</td>
  212. <td width="63%">No</td>
  213. </tr>
  214. <tr>
  215. <td width="337">MailLogger.success.bcc </td>
  216. <td width="63%">Address(es) to send success messages to blind carbon copy (bcc), comma-separated</td>
  217. <td width="63%">No</td>
  218. </tr>
  219. <tr>
  220. <td width="337">MailLogger.failure.subject </td>
  221. <td width="63%">Subject of failed build</td>
  222. <td width="63%">No, default &quot;Build Failure&quot;</td>
  223. </tr>
  224. <tr>
  225. <td width="337">MailLogger.success.subject </td>
  226. <td width="63%">Subject of successful build</td>
  227. <td width="63%">No, default &quot;Build Success&quot;</td>
  228. </tr>
  229. <tr>
  230. <td width="337">MailLogger.failure.body</td>
  231. <td width="63%">Fixed body of the email for a failed
  232. build. <em>Since Ant 1.8.0</em></td>
  233. <td width="63%">No, default is to send the full log output.</td>
  234. </tr>
  235. <tr>
  236. <td width="337">MailLogger.success.body</td>
  237. <td width="63%">Fixed body of the email for a successful
  238. build. <em>Since Ant 1.8.0</em></td>
  239. <td width="63%">No, default is to send the full log output.</td>
  240. </tr>
  241. <tr>
  242. <td width="337">MailLogger.mimeType</td>
  243. <td width="63%">MIME-Type of the message. <em>Since Ant 1.8.0</em></td>
  244. <td width="63%">No, default is text/plain</td>
  245. </tr>
  246. <tr>
  247. <td width="337">MailLogger.charset</td>
  248. <td width="63%">Character set of the message. <em>Since Ant 1.8.0</em></td>
  249. <td width="63%">No</td>
  250. </tr>
  251. <tr>
  252. <td width="337">MailLogger.starttls.enable</td>
  253. <td width="63%">on or true if STARTTLS should be supported
  254. (requires JavaMail). <em>Since Ant 1.8.0</em></td>
  255. <td width="63%">No, default is false</td>
  256. </tr>
  257. <tr>
  258. <td width="337">MailLogger.properties.file </td>
  259. <td width="63%">Filename of properties file that will override other values.</td>
  260. <td width="63%">No</td>
  261. </tr>
  262. </table>
  263. <blockquote>
  264. <p><code>ant -logger org.apache.tools.ant.listener.MailLogger</code></p>
  265. </blockquote>
  266. <h3><a name="AnsiColorLogger">AnsiColorLogger</a></h3>
  267. <p>The AnsiColorLogger adds color to the standard Ant output
  268. by prefixing and suffixing ANSI color code escape sequences to
  269. it. It is just an extension of <a href="#DefaultLogger">DefaultLogger</a>
  270. and hence provides all features that DefaultLogger does.</p>
  271. <p>AnsiColorLogger differentiates the output by assigning
  272. different colors depending upon the type of the message.</p>
  273. <p>If used with the -logfile option, the output file
  274. will contain all the necessary escape codes to
  275. display the text in colorized mode when displayed
  276. in the console using applications like cat, more, etc.</p>
  277. <p>This is designed to work on terminals that support ANSI
  278. color codes. It works on XTerm, ETerm, Win9x Console
  279. (with ANSI.SYS loaded.), etc.</p>
  280. <p><Strong>NOTE:</Strong>
  281. It doesn't work on WinNT and successors, even when a COMMAND.COM console loaded with
  282. ANSI.SYS is used.</p>
  283. <p>If the user wishes to override the default colors
  284. with custom ones, a file containing zero or more of the
  285. custom color key-value pairs must be created. The recognized keys
  286. and their default values are shown below:</p><code><pre>
  287. AnsiColorLogger.ERROR_COLOR=2;31
  288. AnsiColorLogger.WARNING_COLOR=2;35
  289. AnsiColorLogger.INFO_COLOR=2;36
  290. AnsiColorLogger.VERBOSE_COLOR=2;32
  291. AnsiColorLogger.DEBUG_COLOR=2;34</pre></code>
  292. <p>Each key takes as value a color combination defined as
  293. <b>Attribute;Foreground;Background</b>. In the above example, background
  294. value has not been used.</p>
  295. <p>This file must be specified as the value of a system variable
  296. named ant.logger.defaults and passed as an argument using the -D
  297. option to the <b>java</b> command that invokes the Ant application.
  298. An easy way to achieve this is to add -Dant.logger.defaults=
  299. <i>/path/to/your/file</i> to the ANT_OPTS environment variable.
  300. Ant's launching script recognizes this flag and will pass it to
  301. the java command appropriately.</p>
  302. <p>Format:</p><pre>
  303. AnsiColorLogger.*=Attribute;Foreground;Background
  304. Attribute is one of the following:
  305. 0 -&gt; Reset All Attributes (return to normal mode)
  306. 1 -&gt; Bright (Usually turns on BOLD)
  307. 2 -&gt; Dim
  308. 3 -&gt; Underline
  309. 5 -&gt; link
  310. 7 -&gt; Reverse
  311. 8 -&gt; Hidden
  312. Foreground is one of the following:
  313. 30 -&gt; Black
  314. 31 -&gt; Red
  315. 32 -&gt; Green
  316. 33 -&gt; Yellow
  317. 34 -&gt; Blue
  318. 35 -&gt; Magenta
  319. 36 -&gt; Cyan
  320. 37 -&gt; White
  321. Background is one of the following:
  322. 40 -&gt; Black
  323. 41 -&gt; Red
  324. 42 -&gt; Green
  325. 43 -&gt; Yellow
  326. 44 -&gt; Blue
  327. 45 -&gt; Magenta
  328. 46 -&gt; Cyan
  329. 47 -&gt; White</pre>
  330. <blockquote>
  331. <p><code>ant -logger org.apache.tools.ant.listener.AnsiColorLogger</code></p>
  332. </blockquote>
  333. <h3><a name="Log4jListener">Log4jListener</a></h3>
  334. <p><b>Deprecated:</b> Apache Log4j (1) is not developed any more. Last
  335. release is 1.2.17 from 26-May-2012 and contains vulnerability issues.</p>
  336. <p>Passes build events to Log4j, using the full classname's of the generator of
  337. each build event as the category:</p>
  338. <ul>
  339. <li>build started / build finished - org.apache.tools.ant.Project</li>
  340. <li>target started / target finished - org.apache.tools.ant.Target</li>
  341. <li>task started / task finished - the fully qualified classname of the task</li>
  342. <li>message logged - the classname of one of the above, so if a task logs a
  343. message, its classname is the category used, and so on.</li>
  344. </ul>
  345. <p>All start events are logged as INFO.&nbsp; Finish events are either logged as
  346. INFO or ERROR depending on whether the build failed during that stage. Message
  347. events are logged according to their Ant logging level, mapping directly to a
  348. corresponding Log4j level.</p>
  349. <blockquote>
  350. <p><code>ant -listener org.apache.tools.ant.listener.Log4jListener</code></p>
  351. </blockquote>
  352. <p>To use Log4j you will need the Log4j JAR file and a 'log4j.properties'
  353. configuration file. Both should be placed somewhere in your Ant
  354. classpath. If the log4j.properties is in your project root folder you can
  355. add this with <i>-lib</i> option:</p>
  356. <blockquote>
  357. <pre><code>ant -listener org.apache.tools.ant.listener.Log4jListener -lib .</code></pre>
  358. </blockquote>
  359. <p>If, for example, you wanted to capture the same information output to the
  360. console by the DefaultLogger and send it to a file named 'build.log', you
  361. could use the following configuration:</p>
  362. <blockquote>
  363. <pre><code>log4j.rootLogger=ERROR, LogFile
  364. log4j.logger.org.apache.tools.ant.Project=INFO
  365. log4j.logger.org.apache.tools.ant.Target=INFO
  366. log4j.logger.org.apache.tools.ant.taskdefs=INFO
  367. log4j.logger.org.apache.tools.ant.taskdefs.Echo=WARN
  368. log4j.appender.LogFile=org.apache.log4j.FileAppender
  369. log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout
  370. log4j.appender.LogFile.layout.ConversionPattern=[%6r] %8c{1} : %m%n
  371. log4j.appender.LogFile.file=build.log
  372. </code></pre>
  373. </blockquote>
  374. <p>For more information about configuring Log4J see <a href="http://logging.apache.org/log4j/docs/documentation.html">its
  375. documentation page</a>.</p>
  376. <h4>Using the Log4j 1.2 Bridge</h4>
  377. You could use the <a href="http://logging.apache.org/log4j/2.x/log4j-1.2-api/index.html">Log4j Bridge</a>
  378. if your application is written against the Log4j (1.x) API, but you want to use the Log4j 2.x runtime.
  379. For using the bridge with Ant you have to add
  380. <ul>
  381. <li>log4j-1.2-api-${log4j.version}.jar</li>
  382. <li>log4j-api-${log4j.version}.jar</li>
  383. <li>log4j-core-${log4j.version}.jar</li>
  384. <li>log4j2.xml</li>
  385. </ul>
  386. to your classpath (e.g. via the <code>-lib</code> option).
  387. (For using the bridge Ant 1.9.10/1.10.2 or higher is required.)
  388. Translating the 1.x properties file into the 2.x xml syntax would result in
  389. <blockquote>
  390. <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  391. &lt;Configuration status=&quot;WARN&quot;&gt;
  392. &lt;Appenders&gt;
  393. &lt;File name=&quot;file&quot; fileName=&quot;build.log&quot;&gt;
  394. &lt;PatternLayout&gt;
  395. &lt;Pattern&gt;[%6r] %8c{1} : %m%n&lt;/Pattern&gt;
  396. &lt;/PatternLayout&gt;
  397. &lt;/File&gt;
  398. &lt;/Appenders&gt;
  399. &lt;Loggers&gt;
  400. &lt;Root level=&quot;ERROR&quot;&gt;
  401. &lt;AppenderRef ref=&quot;file&quot; level=&quot;DEBUG&quot;/&gt;
  402. &lt;/Root&gt;
  403. &lt;Logger name=&quot;org.apache.tools.ant.Project&quot; level=&quot;INFO&quot;/&gt;
  404. &lt;Logger name=&quot;org.apache.tools.ant.Project&quot; level=&quot;INFO&quot;/&gt;
  405. &lt;Logger name=&quot;org.apache.tools.ant.taskdefs&quot; level=&quot;INFO&quot;/&gt;
  406. &lt;Logger name=&quot;org.apache.tools.ant.taskdefs.Echo&quot; level=&quot;WARN&quot;/&gt;
  407. &lt;/Loggers&gt;
  408. &lt;/Configuration&gt;
  409. </code></pre>
  410. </blockquote>
  411. <h3><a name="XmlLogger">XmlLogger</a></h3>
  412. <p>Writes all build information out to an XML file named log.xml, or the value
  413. of the <code>XmlLogger.file</code> property if present, when used as a
  414. listener. When used as a logger, it writes all output to either the
  415. console or to the value of <code>-logfile</code>. Whether used as a listener
  416. or logger, the output is not generated until the build is complete, as it
  417. buffers the information in order to provide timing information for task,
  418. targets, and the project.</p>
  419. <p>By default the XML file creates a reference to an XSLT file "log.xsl" in the current directory;
  420. look in ANT_HOME/etc for one of these. You can set the property
  421. <code>ant.XmlLogger.stylesheet.uri</code> to provide a uri to a style sheet.
  422. this can be a relative or absolute file path, or an http URL.
  423. If you set the property to the empty string, "", no XSLT transform
  424. is declared at all.</p>
  425. <blockquote>
  426. <p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br>
  427. <code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p>
  428. </blockquote>
  429. <h3><a name="TimestampedLogger">TimestampedLogger</a></h3>
  430. <p>
  431. Acts like the default logger, except that the final success/failure message also includes
  432. the time that the build completed. For example:
  433. </p>
  434. <pre>
  435. BUILD SUCCESSFUL - at 16/08/05 16:24
  436. </pre>
  437. <p>To use this listener, use the command:</p>
  438. <blockquote>
  439. <code>ant -logger org.apache.tools.ant.listener.TimestampedLogger</code>
  440. </blockquote>
  441. <h3><a name="BigProjectLogger">BigProjectLogger</a></h3>
  442. <p>
  443. This logger is designed to make examining the logs of a big build easier,
  444. especially those run under continuous integration tools. It
  445. </p>
  446. <ol>
  447. <li>When entering a child project, prints its name and directory</li>
  448. <li>When exiting a child project, prints its name</li>
  449. <li>Includes the name of the project when printing a target</li>
  450. <li>Omits logging the names of all targets that have no direct task output</li>
  451. <li>Includes the build finished timestamp of the TimeStamp logger</li>
  452. </ol>
  453. <p>
  454. This is useful when using &lt;subant&gt; to build a large project
  455. from many smaller projects -the output shows which particular
  456. project is building. Here is an example in which "clean" is being called
  457. on all a number of child projects, only some of which perform work:
  458. </p>
  459. <pre>
  460. ======================================================================
  461. Entering project "xunit"
  462. In /home/ant/components/xunit
  463. ======================================================================
  464. xunit.clean:
  465. [delete] Deleting directory /home/ant/components/xunit/build
  466. [delete] Deleting directory /home/ant/components/xunit/dist
  467. ======================================================================
  468. Exiting project "xunit"
  469. ======================================================================
  470. ======================================================================
  471. Entering project "junit"
  472. In /home/ant/components/junit
  473. ======================================================================
  474. ======================================================================
  475. Exiting project "junit"
  476. ======================================================================
  477. </pre>
  478. <p>
  479. The entry and exit messages are very verbose in this example, but in
  480. a big project compiling or testing many child components, the messages
  481. are reduced to becoming clear delimiters of where different projects
  482. are in charge -or more importantly, which project is failing.
  483. </p>
  484. <p>To use this listener, use the command:</p>
  485. <blockquote>
  486. <code>ant -logger org.apache.tools.ant.listener.BigProjectLogger</code>
  487. </blockquote>
  488. <h3><a name="SimpleBigProjectLogger">SimpleBigProjectLogger</a></h3>
  489. <p>Like <code>BigProjectLogger</code>, project-qualified target names are printed,
  490. useful for big builds with subprojects.
  491. Otherwise it is as quiet as <code>NoBannerLogger</code>:</p>
  492. <pre>
  493. Buildfile: /sources/myapp/build.xml
  494. myapp-lib.compile:
  495. Created dir: /sources/myapp/lib/build/classes
  496. Compiling 1 source file to /sources/myapp/lib/build/classes
  497. myapp-lib.jar:
  498. Building jar: /sources/myapp/lib/build/lib.jar
  499. myapp.compile:
  500. Created dir: /sources/myapp/build/classes
  501. Compiling 2 source files to /sources/myapp/build/classes
  502. myapp.jar:
  503. Building jar: /sources/myapp/build/myapp.jar
  504. BUILD SUCCESSFUL
  505. Total time: 1 second
  506. </pre>
  507. <p><b>since Ant 1.8.1</b></p>
  508. <p>To use this listener, use the command:</p>
  509. <blockquote>
  510. <code>ant -logger org.apache.tools.ant.listener.SimpleBigProjectLogger</code>
  511. </blockquote>
  512. <h3><a name="ProfileLogger">ProfileLogger</a></h3>
  513. <p>This logger stores the time needed for executing a task, target and the whole build and prints
  514. these information. The output contains a timestamp when entering the build, target or task and a timestamp and the needed time when exiting.
  515. </p>
  516. <!-- This is the 'since' as described in the Loggers JavaDoc -->
  517. <p><b>since Ant 1.8.0</b></p>
  518. <h4>Example</h4>
  519. Having that buildfile
  520. <pre>
  521. &lt;project&gt;
  522. &lt;target name=&quot;aTarget&quot;&gt;
  523. &lt;echo&gt;echo-task&lt;/echo&gt;
  524. &lt;zip destfile=&quot;my.zip&quot;&gt;
  525. &lt;fileset dir=&quot;${ant.home}&quot;/&gt;
  526. &lt;/zip&gt;
  527. &lt;/target&gt;
  528. &lt;target name=&quot;anotherTarget&quot; depends=&quot;aTarget&quot;&gt;
  529. &lt;echo&gt;another-echo-task&lt;/echo&gt;
  530. &lt;/target&gt;
  531. &lt;/project&gt;
  532. </pre>
  533. and executing with <tt>ant -logger org.apache.tools.ant.listener.ProfileLogger anotherTarget</tt> gives that output (with other timestamps and duration of course ;) :
  534. <pre>
  535. Buildfile: ...\build.xml
  536. Target aTarget: started Thu Jan 22 09:01:00 CET 2009
  537. echo: started Thu Jan 22 09:01:00 CET 2009
  538. [echo] echo-task
  539. echo: finished Thu Jan 22 09:01:00 CET 2009 (250ms)
  540. zip: started Thu Jan 22 09:01:00 CET 2009
  541. [zip] Building zip: ...\my.zip
  542. zip: finished Thu Jan 22 09:01:01 CET 2009 (1313ms)
  543. Target aTarget: finished Thu Jan 22 09:01:01 CET 2009 (1719ms)
  544. Target anotherTarget: started Thu Jan 22 09:01:01 CET 2009
  545. echo: started Thu Jan 22 09:01:01 CET 2009
  546. [echo] another-echo-task
  547. echo: finished Thu Jan 22 09:01:01 CET 2009 (0ms)
  548. Target anotherTarget: finished Thu Jan 22 09:01:01 CET 2009 (0ms)
  549. BUILD SUCCESSFUL
  550. Total time: 2 seconds
  551. </pre>
  552. <h2><a name="dev">Writing your own</a></h2>
  553. <p>See the <a href="develop.html#buildevents">Build Events</a> section for
  554. developers.</p>
  555. <p>Notes:</p>
  556. <ul>
  557. <li>
  558. A listener or logger should not write to standard output or error in the <code>messageLogged()</code> method;
  559. Ant captures these internally and it will trigger an infinite loop.
  560. </li>
  561. <li>
  562. Logging is synchronous; all listeners and loggers are called one after the other, with the build blocking until
  563. the output is processed. Slow logging means a slow build.
  564. </li>
  565. <li>When a build is started, and <code>BuildListener.buildStarted(BuildEvent event)</code> is called,
  566. the project is not fully functional. The build has started, yes, and the <code>event.getProject()</code> method call
  567. returns the Project instance, but that project is initialized with JVM and ant properties, nor has it
  568. parsed the build file yet. You cannot call <code>Project.getProperty()</code> for property lookup, or
  569. <code>Project.getName()</code> to get the project name (it will return null).
  570. </li>
  571. <li>
  572. Classes that implement <code>org.apache.tools.ant.SubBuildListener</code> receive notifications when child projects
  573. start and stop.
  574. </li>
  575. </ul>
  576. </body>
  577. </html>