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

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