1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
4
<title>NAnt - Loggers & Listeners</title>
5
<meta http-equiv="Content-Language" content="en-ca" />
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
<meta name="description" content="Loggers & Listeners" />
8
<link rel="stylesheet" type="text/css" href="../style.css" />
9
<style type="text/css">
32
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="NavBar">
34
<td class="NavBar-Cell">
35
<a title="NAnt home page" href="http://nant.sourceforge.net"><b>NAnt</b></a> <img src="../images/arrow.gif" alt="->" width="13" height="9" />
36
<a href="../index.html">Help</a> <img alt="->" src="../images/arrow.gif"/> <a href="index.html">
37
Fundamentals</a> <img height="9" alt="->" src="../images/arrow.gif" width="13" />
38
Loggers & Listeners
40
<td class="NavBar-Cell" align="right">
45
<h1>Loggers & Listeners</h1>
49
NAnt has two related features to allow the build process to be monitored:
50
listeners and loggers.
54
A listener is alerted of the following events:
80
Loggers extend the capabilities of listeners and add the following features:
84
Receives a handle to the standard output and error print streams and therefore
85
can log information to the console or the <code>-logfile</code>
89
Logging level (<code>-quiet</code>, <code>-verbose</code>, <code>-debug</code>)
93
Emacs-mode aware. This still needs to be implemented.
96
<h2>Built-in Listeners/Loggers</h2>
102
<col style="TEXT-ALIGN: center" />
114
<td><a href="#DefaultLogger">NAnt.Core.DefaultLogger</a></td>
116
The logger used implicitly unless overridden with the <code>-logger</code> command-line
119
<td>IBuildLogger</td>
122
<td><a href="#MailLogger">NAnt.Core.MailLogger</a></td>
124
Extends <a href="#DefaultLogger">DefaultLogger</a> such that output is still
125
generated the same, and when the build is finished an e-mail can be sent.
127
<td>IBuildLogger</td>
130
<td><a href="#XmlLogger">NAnt.Core.XmlLogger</a></td>
132
Generates output in XML format.
134
<td>IBuildLogger</td>
139
<h3><a id="DefaultLogger" />DefaultLogger</h3>
140
<p>Simply run NAnt normally, or:</p>
142
<p><code>NAnt.exe -logger:NAnt.Core.DefaultLogger</code></p>
144
<h3><a id="MailLogger" />MailLogger</h3>
146
The MailLogger captures all output logged through DefaultLogger (standard NAnt
147
output) and will send success and failure messages to unique e-mail lists, with
148
control for turning off success or failure messages individually.
150
<p>Properties controlling the operation of MailLogger are:</p>
168
<td>MailLogger.mailhost</td>
169
<td>The SMTP server to use.</td>
170
<td>No, default is "localhost"</td>
173
<td>MailLogger.from</td>
174
<td>The address of the e-mail sender.</td>
175
<td>Yes, if mail needs to be sent.</td>
178
<td>MailLogger.failure.notify</td>
179
<td>Send build failure e-mails ?</td>
180
<td>No, default is "true".</td>
183
<td>MailLogger.success.notify</td>
184
<td>Send build success e-mails ?</td>
185
<td>No, default is "true".</td>
188
<td>MailLogger.failure.to</td>
189
<td>The address to send build failure messages to.</td>
190
<td>Yes, if failure mail is to be sent.</td>
193
<td>MailLogger.success.to</td>
194
<td>The address to send build success messages to.</td>
195
<td>Yes, if success mail is to be sent.</td>
198
<td>MailLogger.failure.subject</td>
199
<td>The subject of build failure messages.</td>
200
<td>No, default is "Build Failure".</td>
203
<td>MailLogger.success.subject</td>
204
<td>The subject of build success messages.</td>
205
<td>No, default is "Build Success".</td>
208
<td>MailLogger.failure.attachments</td>
209
<td>The ID of a fileset representing a set of files to attach when the build fails.</td>
213
<td>MailLogger.success.attachments</td>
214
<td>The ID of a fileset representing a set of files to attach when the build is successful.</td>
218
<td>MailLogger.body.encoding</td>
219
<td>The encoding type of the body of the e-mail message.</td>
220
<td>No, default is system's ANSI code page.</td>
223
<td>MailLogger.smtp.username<sup>1</sup></td>
224
<td>The name of the user to login to the SMTP server.</td>
228
<td>MailLogger.smtp.password<sup>1</sup></td>
229
<td>The password of the specified user.</td>
233
<td>MailLogger.smtp.enablessl<sup>1</sup></td>
234
<td>Specifies whether to use SSL to encrypt the connection.</td>
235
<td>No, default is "false".</td>
238
<td>MailLogger.smtp.port<sup>1</sup></td>
239
<td>The SMTP server port to connect to.</td>
240
<td>No, default is "25".</td>
244
<p><sup>1</sup> Only available when NAnt is built targeting .NET Framework 1.1 (or equivalent) or higher.</p>
248
<p><code>NAnt.exe -logger:NAnt.Core.MailLogger</code></p>
252
<span class="xmltext"><</span><span class="xmlelement">project</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger Test"</span> <span class="xmlattribute">default</span><span class="xmltext">="build"></span>
253
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.mailhost"</span> <span class="xmlattribute">value</span><span class="xmltext">="smtp.wherever.be" /></span>
254
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.from"</span> <span class="xmlattribute">value</span><span class="xmltext">="me@telenet.be" /></span>
255
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.failure.notify"</span> <span class="xmlattribute">value</span><span class="xmltext">="true" /></span>
256
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.success.notify"</span> <span class="xmlattribute">value</span><span class="xmltext">="true" /></span>
257
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.failure.to"</span> <span class="xmlattribute">value</span><span class="xmltext">="support@home.be" /></span>
258
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.success.to"</span> <span class="xmlattribute">value</span><span class="xmltext">="support@home.be" /></span>
259
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.failure.subject"</span> <span class="xmlattribute">value</span><span class="xmltext">="Nightly build failure !" /></span>
260
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.success.subject"</span> <span class="xmlattribute">value</span><span class="xmltext">="Nightly build successful" /></span>
261
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.failure.attachments"</span> <span class="xmlattribute">value</span><span class="xmltext">="MailLogger.failure.files" /></span>
262
<span class="xmltext"><</span><span class="xmlelement">property</span> <span class="xmlattribute">name</span><span class="xmltext">="MailLogger.success.attachments"</span> <span class="xmlattribute">value</span><span class="xmltext">="MailLogger.success.files" /></span>
264
<span class="xmlcomment"><!-- set of files to attach when build fails --></span>
265
<span class="xmltext"><</span><span class="xmlelement">fileset</span> <span class="xmlattribute">id</span><span class="xmltext">="MailLogger.failure.files"></span>
266
<span class="xmltext"><</span><span class="xmlelement">include</span> <span class="xmlattribute">name</span><span class="xmltext">="dump.log" /></span>
267
<span class="xmltext"><</span><span class="xmlelement">include</span> <span class="xmlattribute">name</span><span class="xmltext">="trace.txt" /></span>
268
<span class="xmltext"></</span><span class="xmlelement">fileset</span><span class="xmltext">></span>
270
<span class="xmlcomment"><!-- set of files to attach when build is successful --></span>
271
<span class="xmltext"><</span><span class="xmlelement">fileset</span> <span class="xmlattribute">id</span><span class="xmltext">="MailLogger.success.files"></span>
272
<span class="xmltext"><</span><span class="xmlelement">include</span> <span class="xmlattribute">name</span><span class="xmltext">="trace.txt" /></span>
273
<span class="xmltext"></</span><span class="xmlelement">fileset</span><span class="xmltext">></span>
275
<span class="xmltext"><</span><span class="xmlelement">target</span> <span class="xmlattribute">name</span><span class="xmltext">="build"></span>
276
<span class="xmltext"><</span><span class="xmlelement">echo</span> <span class="xmlattribute">message</span><span class="xmltext">="Starting build" /></span>
278
<span class="xmltext"><</span><span class="xmlelement">echo</span> <span class="xmlattribute">message</span><span class="xmltext">="Finished build" /></span>
279
<span class="xmltext"></</span><span class="xmlelement">target</span><span class="xmltext">></span>
280
<span class="xmltext"></</span><span class="xmlelement">project</span><span class="xmltext">></span>
282
<h3><a id="XmlLogger" />XmlLogger</h3>
284
Writes all build information out to an XML file named <code>log.xml</code>, or
285
the value of the <code>XmlLogger.file</code> property if present, when used as
286
a listener. When used as a logger, it writes all output to either the console
287
or to the value of <code>-logfile</code>.
290
Whether used as a listener or logger, the output is not generated until the
296
<code>NAnt.exe -listener:NAnt.Core.XmlLogger</code><br />
297
<code>NAnt.exe -logger:NAnt.Core.XmlLogger -logfile:buildlog.xml</code>
302
<span class="xmltext"><</span><span class="xmlelement">buildresults</span> <span class="xmlattribute">project</span><span class="xmltext">="test"></span>
303
<span class="xmltext"><</span><span class="xmlelement">message</span> <span class="xmlattribute">level</span><span class="xmltext">="Info"><![</span><span class="xmlcdata">CDATA[Buildfile: file:///D:/nant-test/xmlpeek/default.build]]</span><span class="xmltext">></</span><span class="xmlelement">message</span><span class="xmltext">></span>
304
<span class="xmltext"><</span><span class="xmlelement">message</span> <span class="xmlattribute">level</span><span class="xmltext">="Info"><![</span><span class="xmlcdata">CDATA[Target framework: Microsoft .NET Framework 1.1]]</span><span class="xmltext">></</span><span class="xmlelement">message</span><span class="xmltext">></span>
305
<span class="xmltext"><</span><span class="xmlelement">message</span> <span class="xmlattribute">level</span><span class="xmltext">="Info"><![</span><span class="xmlcdata">CDATA[Target<span class="xmltext">(</span>s<span class="xmltext">)</span> specified: build]]</span><span class="xmltext">></</span><span class="xmlelement">message</span><span class="xmltext">></span>
306
<span class="xmltext"><</span><span class="xmlelement">target</span> <span class="xmlattribute">name</span><span class="xmltext">="build"></span>
307
<span class="xmltext"><</span><span class="xmlelement">task</span> <span class="xmlattribute">name</span><span class="xmltext">="xmlpeek"></span>
308
<span class="xmltext"><</span><span class="xmlelement">message</span> <span class="xmlattribute">level</span><span class="xmltext">="Info"><![</span><span class="xmlcdata">CDATA[Peeking at <span class="xmltext">'D:\nant-test\xmlpeek\input.xml'</span> with XPath expression <span class="xmltext">'x:parameters/x:param'</span>.]]</span><span class="xmltext">></</span><span class="xmlelement">message</span><span class="xmltext">></span>
309
<span class="xmltext"><</span><span class="xmlelement">message</span> <span class="xmlattribute">level</span><span class="xmltext">="Info"><![</span><span class="xmlcdata">CDATA[Found <span class="xmltext">'1'</span> nodes with the XPath expression <span class="xmltext">'x:parameters/x:param'</span>.]]</span><span class="xmltext">></</span><span class="xmlelement">message</span><span class="xmltext">></span>
310
<span class="xmltext"><</span><span class="xmlelement">duration</span><span class="xmltext">></span><span style="color: black;">15.625</span><span class="xmltext"></</span><span class="xmlelement">duration</span><span class="xmltext">></span>
311
<span class="xmltext"></</span><span class="xmlelement">task</span><span class="xmltext">></span>
312
<span class="xmltext"><</span><span class="xmlelement">duration</span><span class="xmltext">></span><span style="color: black;">15.625</span><span class="xmltext"></</span><span class="xmlelement">duration</span><span class="xmltext">></span>
313
<span class="xmltext"></</span><span class="xmlelement">target</span><span class="xmltext">></span>
314
<span class="xmltext"><</span><span class="xmlelement">duration</span><span class="xmltext">></span><span style="color: black;">31.25</span><span class="xmltext"></</span><span class="xmlelement">duration</span><span class="xmltext">></span>
315
<span class="xmltext"></</span><span class="xmlelement">buildresults</span><span class="xmltext">></span>