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 Fri, 05 Apr 2002 23:09:07 GMT

On Fri, 5 Apr 2002, Geir Magnusson Jr. wrote:

> I looked for docs on how to setup the web.xml for tc4 to specify my ctx
> factory, but didn't find them when I looked.  I assume they are there
> somewhere?

Short answer:  You don't configure the factory in web.xml -- that goes in
server.xml.  See the jndi-resource-howto.html page for the details.

Longer answer (assuming you really want a LogFactory instead, which is
more likely, but the concepts are all the same):

(1)  In web.xml, declare the fact that you need a LogFactory instance:

            The log factory instance for this web application.

    (You could also use a <resource-ref>, but that has some additional
    required elements that are not really relevant for this purpose)

(2)  In server.xml, define a corresponding resource definition, including
     a declaration of the javax.naming.spi.ObjectFactory implementation:

    <Context path="/myapp" ...>
        <Resource name="log/Factory" auth="Container"
        <ResourceParams name="log/Factory">
                <value>...ObjectFactory implementation class...</value>
            ... other configuration parameters for your factory ...

    (In the nightly builds, there's an additional notion called
    "global JNDI resources" so that you can share resources across
    webapps if you want to.)

    (Note that this configuration is done *totally* separate from the
    web application itself -- so you can change it without going and
    messing with web.xml or other configuration properties files.)

(3) Implement the javax.naming.spi.ObjectFactory class, and stick it in
    a JAR file in $CATALINA_HOME/server/lib (or unpacked under
    $CATALINA_HOME/server/classes).  There's an example down near the
    bottom of the jndi-resources-howto.html page in the Tomcat docs.

    The actual object you make available could either be the standard
    o.a.c.l.LogFactory class, or a subclass of that class that does
    Log instantiation differently.  Your choice (as system administrator
    -- the application author neither knows nor cares).

(4) Use this LogFactory in your application to create loggers:

    InitialContext context = new InitialContext();
    LogFactory logFactory = (LogFactory)
    Log log = logFactory.getInstance("");"Hello, world");
    mycomponent.setLog(log); // Or whatever

    (Note that you can even do this sort of thing inside a JavaBean.
    No reference to the ServletContext or any static method is needed.
    Just ignore the static getFactory() and getLog() methods on
    o.a.c.l.LogFactory :-)

> --
> Geir Magnusson Jr.             
> System and Software Consulting
> You're going to end up getting pissed at your software
> anyway, so you might as well not pay for it. Try Open Source.


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

View raw message