Simon Kitching wrote:

On Tue, 2003-10-21 at 10:29, robert burrell donkin wrote:


On Sunday, October 5, 2003, at 10:53 PM, Simon Kitching wrote:

<snip>



Hmm .. but calling Digester.setLogger probably doesn't override the
object known to the LogFactory...

What exactly is the purpose of being able to set the Log object used by
a class or instance?


so the instance used to log by digester can be set programmatically at runtime. this is a useful feature because:

1. it's a very convenient way to bypass the usual commons-logging configuration infrastructure. for example, it's often easier (when debugging) to setLogger programmatically on a particular instance than to reconfigure everything.



Easier than changing the logging config file for the appropriate logging implementation (eg the log4j.properties or log4j.xml file)?



No.

Consider a use case like Tomcat, where Digester is used both by the container (to parse server.xml and web.xml files) and also by an application (say, Struts reading struts-config.xml). It's entirely reasonable to for someone to want the digester log output for the container's use of Digester to go to the container's logging hierarchy, and the webapp's use of Digester to log to a webapp hierarchy.

2. it allows digester to participate properly in frameworks based on inversion-of-control. (frameworks of this type are configured and controlled in a parent-child fashion. the Log to be used by a digester should be controlled by the component owning digester)



This approach requires:


(a) The framework to call setLog on each component used by the framework
which has a dedicated Log object.



*Allows* not *requires*. If you don't call setLog() you get the default names.


Imagine a framework which uses
Digester + Net + CLI, where each component works like Digester,
requiring the user to call setLog on each one in turn.

(b) Requiring classes to log via some object stored on some "main" object in
the component, like all classes in the Digester project are required to
get the Log object from their owning Digester object. In fact, in many
projects this will not be feasable; it only works in Digester because
every object of interest happens to have a reference to an owning
Digester object.




*Allows* not *requires*. If you don't call setLog() you get the default names.

Isn't it much cleaner for the calling framework to set up an appropriate
implementation of org.apache.commons.loggging.Logfactory that does
whatever the "framework" wants with respect to logging? If the calling
framework wants all logging (regardless of category) to go to one
destination, then it creates a LogFactory implementation which returns a
single Log object always, and that Log object's implementation writes to
the desired destination.




Can you show me how you'd solve the problem posed above about Tomcat? Especially in the case where you're running in a restricted environment where you are not allowed to modify the LogFactory in the container itself?


All those getLog and setLog calls go away. Objects don't need to have
references to the "master" object which holds the Log object to use.
Objects log via their own Category, so that filtering can be applied
appropriately.



Thoughts??

Regards,

Simon




If you go back in the commons-dev message archives, you'll find that the reason setLog exists in the first place is because the Avalon folks (who know a little about IoC :-) said they needed it. You seem to be arguing the opposite position, which is kinda interesting. But, at the end of the day, I can't see why having an optional method to set the Log object a Digester instance can use causes you any grief if you never call it.


Craig



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to