Hi All,

I have implemented Xml Logging for use on an upcoming project, and so I
wanted to submit a patch and the files in the in the event that the nant
maintainers find it goes in the direction they have envisioned for logging.
My hope is that it provides a good foundation for that effort.

I based the event structure on Ant 1.5's implementation of events, as they
fit my needs and allow the use of Log4Net (Ant 1.5 has a listener for
LogForJ) as Scott described.

The files I have attached represent first pass at Xml (and event-based)
logging. Along the way I have kept the code base entirely backward
compatible (i.e. the ConsoleLogger works like it always did). My other
goals were minimalism, and least-invasive.

Here's what I added:
An interface IBuildEventConsumer that defines a set of events (defined in
Log.cs)
A new subtype of LogListener called XmlLogger (in XmlLogger.cs) that also
implements the IBuildEventConsumer interface
A BuildEventArgs class that represents a build event (defined in Log.cs)
A cmd line option for specifying the logger -logger:type name (e.g.
SourceForge.NAnt.XmlLogger)
a cmd line option for specifying a log file -logfile:fileName
A bunch of unit tests

A set of delegate based events and OnEvent methods (defined statically in
Project.cs)
Calling of those events wrapping Build start and finish (in Project.cs)
Target start and finish (Target.cs) and Task start and finish (Task.cs)

The result is a build report that is informationally the same as the
console output, but in an xml format.

Here's what I might add at some point to our version (although it meets our
needs now) -- and if the code finds its way into the next NAnt release,
what others might like to look at:
* Add more event args  (e.g migrating the BUILD SUCCEEDED and other success
metrics for use by the BuildFinished event)
* Finish migrating to event-based logging. Right now its sort of a hybrid
-- XmlLogger implements the six events, but still uses the Write* methods
of LogListener to handle messages. Two additional events: say
MessageFragment and Message would complete the migration.
* Remove the call in Target that prints the name of the target out and
reimplement as the TargetStarted method on ConsoleLogger (after specifying
that it implements IBuildEventConsumer)
* Refactor the Main function in NAnt.cs (its doing a lot now) so that the
property info is more robust, and some of the logging code that is
currently inline moved to its own methods
* Revisit how the file for logging gets created.
* Remove the formatting from the Log.Write* calls and do this formatting in
the appropriate events in ConsoleLogger
* Change the Loggers into listeners (ala Ant) and also allow a single
Logger (ala Ant)
* Make it possible to specify multiple listeners on the cmd line (i.e the
logfile attribute would go with the logger not the listeners). Currently
(in the mod) if you specify a logger on the cmd line it replaces the
default Logger. The Log class's round robin implementation is unchanged,
but unused for this implementation.
* Remove the logging round robin code (which makes a lot of assumptions
about formatting and logger needs) and take full advantage of Event
multicasting which does more or less the same thing but in a less coupled
fashion.
* Other miscellaneous refactorings that remove assumptions about what it
means to listen and log the build

Whew, that got a bit long, hope someone finds this useful.

Best,
Bill

Contents:
xmllogging080202wec.patch: patch file of changes made to existing NAnt code
base (cvs diff -u)
XmlLogger.cs:  XmlLogger implementation (I had it in the the src/NAnt/Util
directory)
XmlLoggerTest.cs: unit tests (I had it in the src/NAnt.Tests/Util
directory)

(See attached file: XmlLogging.zip)






Attachment: XmlLogging.zip
Description: Zip archive

Reply via email to