Hi Scott,

Sorry that this got a little long, but as you will see I have been thinking
about this a lot lately :-)

I have been chewing on this since last week when I asked about what it
would take to get an xml log. After trading emails with the list, I took a
look at Ant for inspiration and found that Ant 1.5 has an event system very
similar to what you've described, except that they include another event
for messages.

The code that Gerry posted seems to point that way as well -- but I haven't
dug into yet.

As I mentioned recently, we are working on a port/rewrite of CruiseControl
for the .NET platform. While implementing a class to drive NAnt, we
realized that we couldn't get an XML report of the results back to merge
with the rest of our workflow execution report.

So I had been considering implementing something similar to what you
describe in order to get us past our roadblock, and hopefully help NAnt
mature its logging.

Here are my thoughts so far:

I agree with both of these statements:
Events and logs serve a different purpose.
Something like Log4Net would be very nice instead of writing one.

The way I see it though, these two items are not completely unrelated. For
example, if one were to want to produce an XML result of an execution, it
would be very effective to create the log by using events at the beginning
and end of each target/task to create elements for each of them in the
resultant XML.

In order to facilitate this sort of log building an XML logger would need
be no more than just another event handler. Implementing this or other
types of logging classes using Log4Net would then be an implementation
detail of an event handling class, and not known throughout NAnt's code.
Another advantage of this is that if someone wanted a simpler logger (or to
use some other logging tool) they could simply implement the Logger
interface, and they'd be off and running (In Ant 1.5 Loggers appear to be
an extension of listeners, but I haven't looked at it in detail).

What NAnt has now is explicit logging, possibly to multiple loggers but
with no way for the loggers to know the context of what is being logged.

What we seem to want to go is toward explicit event notification with
Logging being a valid listener and the ability to easily specify
additional/different listeners.

This isn't too huge of a difference from where NAnt is now. The problem I
see, is getting from here to there. There are a couple of things that make
this a non-trivial exercise:

1)Currently the Logger is explicitly mentioned in every target and task.
2)The formatting of the message for the console is expressed at each Log
invocation.
3)There is no non-programmatic way of specifying additional
Logger/Listeners
4)Messages being raised as events would require large changes

And a couple of things in our favor:
1)Logger is already abstracted
2)The code is already structured for multiple LoggerListeners

So, as I scoped this out last week, I came up with the following tasks for
preparing the code to support an XML event handler/Logger:

1) factor all log statements that use LogPrefix, pushing this behavior down
to the specific LoggerListener (in this case ConsoleLogger)
This can be done by adding an Element parameter in an overload to the Write
and WriteLine methods in Log and LoggerListener.

2) Implement events at build start, build end, target start, target end by
changing Project.Execute, Target.Execute and Task.Execute

3) Modify LoggerListeners to implement EventHandling methods

4) add a command line argument for specifying additional listeners (e.g.
-listener xml)

5) modify Log class to allow adding listeners to the _listeners collection

6) register event handlers for each listener for each event

7) in ListenerLogger event handlers emit appropriate text on event.

8) remove log calls for targets (it will be provided via handler) and in
ConsoleLogger implement onTargetStart to emit TargetName:

I actually implemented step one for a few tasks, and verified that it
works.

Once completing all 8 steps, the code would work as it does now, but adding
XML Logging would be a simple matter of adding an XML LoggerListener and a
line to the command line args to support it.

>From there it would be a matter of removing all the calls to Log and
replacing them with a message event to complete the migration to
event-based notifications. Once that is complete it should be easy to add a
Log4NetListener that used Log4Net to accomplish logging.

-- Or at least it would be like that according to what i have learned so
far, those next 7 steps might change my mind a bit.

I was tentatively planning on doing the rest of that refactoring starting
tomorrow (because we need to demo CruiseControl in a couple of weeks). My
very next step was to look at Gerry's code in more detail, and then start
on steps 2 & 3 above.

Best,
Bill



                                                                                       
                                                               
                      "Scott Hernandez"                                                
                                                               
                      <[EMAIL PROTECTED]>                       To:       
"'Nant-Developers \(E-mail\)'" <[EMAIL PROTECTED]>        
                      Sent by:                                cc:                      
                                                               
                      [EMAIL PROTECTED]        Subject:  [nant-dev] 
Logging and Events                                                 
                      ceforge.net                                                      
                                                               
                                                                                       
                                                               
                                                                                       
                                                               
                      07/22/2002 02:46 PM                                              
                                                               
                                                                                       
                                                               
                                                                                       
                                                               




I've been giving some thought to logging and an event system for nant. I
don't think these two systems should be the same. They serve two different
purposes and don't need to overlap.

In my mind logging should be done via a mature logger, and it would be
great if we didn't have to write it. I'd like to suggest that we use
Log4Net.

As for events, it seems like the following are probably going to be
important:

Build Start/End
Target Start/End
Task Start/End

It would also be nice for the event system to allow for interception and
cancel-ability.

Thoughts?






-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to