commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [logging] Need interface... VOTE
Date Sat, 06 Apr 2002 17:14:48 GMT

On Sat, 6 Apr 2002, Geir Magnusson Jr. wrote:

> I'm trying the Service provider approach (can't find the 'Service' class
> anywhere in the 1.3.1 docs, but that's a different issue...) by making an
> alternative impl of LogFactory and putting the proper META-INF/services path
> in the jar.
> I still can't see how classpath order for alternate LogFactory impls isn't
> going to be a problem with something canonical like Digester or other
> commons components, but at this point I trust that y'all have thought this
> through and I just need to go convince myself.

Try it, you'll like it.  :-)

One of my internal tests of this concept was an application where the
logger names were required to all fall under a particular package name
prefix.  Rather than go modify the log names requested by all the
components, I wrote a simple LogFactory implementation that overrode the
newInstance() method and put the right prefix on the front (without any
components knowing better).  It worked pretty slick.

I could have just as easily ignored the name specified by the components
and used a single common Log instance - essentially equivalent to what
your setLog() method would do, but (again) without requiring any muss and
fuss on the components actually using the logging.

Best of all, in Tomcat 4, the auto-magical stuff works on a per-webapp
basis so each webapp can have their own LogFactory if they want it (and
default to the standard one if they don't).

> Still seems like magic, but we all know what Arthur C Clark said about
> magic..

It definitely takes a few passes through the factory finder code to "get
it" (I didn't believe it the first time, either :-) -- but the concept is
quite powerful.

> Thanks all.
> geir


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message