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

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