You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "David Tonhofer, m-plify S.A." <d....@m-plify.com> on 2004/01/13 13:26:34 UTC

Re: Serious letdown when trying to log4j in Tomcat. Unsolvable? (Solved)

--On Monday, January 12, 2004 11:27 PM -0600 Jacob Kjome <ho...@visi.com> 
wrote:

>>The gist:
>>
>>  "In some (most?) cases you cannot use a 'log4j.properties'
>>   file placed in your web application's WEB-INF/classes
>>   directory"

> Who are you quoting?

Well, myself of course ;-)

>>...this goes counter to the Log4J's documentation, which says:
>>
>>  "The default log4j initialization is particularly useful in web-server
>>  environments. Under Tomcat 3.x and 4.x, you should place the
>>  log4j.properties under the WEB-INF/classes directory of your
>>  web-applications. Log4j will find the properties file and initialize
>>  itself. This is easy to do and it works."

> Well, it works fine....as long as you *also* add log4j.jar to WEB-INF/lib.
> I bet you didn't do that, did you. :-)

Actually, no.

> True, WEB-INF/classes/log4j.properties is irrelevant to 
common/lib/log4j.jar.
> However, it is *entirely* relevant to WEB-INF/lib/log4j.jar.  Because of 
the
> class loading behavior of webapps, any webapp with log4j.jar in its own
> WEB-INF/lib will run its default logger repository in an entirely
> self-contained environment completely separated from that of the server or
> other apps.

Ah...good idea! I didn't think of that. The "greedy" webapp classloader
will have its own log4j 'universe' (classes *and* logging hierarchy), while
classloaders higher up the classloader hierarchy are unaffected. You must
not forget to also add commons-logging jars if you log through 
commons-logging.

Thus, let's summarize:

Default setup for Tomcat:

  tomcat4.1.24/common/lib/commons-logging.jar
  tomcat4.1.24/common/lib/commons-logging-api.jar
  tomcat4.1.24/common/lib/log4j.jar
  tomcat4.1.24/common/classes/log4j.properties

Setup for webapp using commons-logging with log4j underneath:

  my_webapp/WEB-INF/lib/commons-logging.jar
  my_webapp/WEB-INF/lib/commons-logging-api.jar
  my_webapp/WEB-INF/lib/log4j.jar
  my_webapp/WEB-INF/classes/log4j.properties

Once Tomcat starts up, commons-logging and log4j initialization (if any)
will be done through the Common classloader and the log4j.properties
file accessible to the common classloader. All classes loaded from the
Shared, Catalina and Common classloaders will 'see' that setup.

Once the webapp starts up, the Webapp classloader (greedy) will
restart its own initialization of commons-logging and log4j as these
classes are directly available to it. It will use the log4j.properties
file in its classes subdirectory. All classes loaded by the Webapp
classloader will 'see' that setup.

Classloader reference:

       Bootstrap
           |
        System
           |
           |
        Common
         /  \
        /    \
       /      \
   Catalina    |
            Shared
              / \
             /   \
       Webapp1  Webapp2

> Jake

Thanks Jake.

David.

P.S. But shouldn't there be a notice in the log4j documentation?







---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Serious letdown when trying to log4j in Tomcat. Unsolvable? (Solved)

Posted by Jacob Kjome <ho...@visi.com>.
Quoting "David Tonhofer, m-plify S.A." <d....@m-plify.com>:

> --On Monday, January 12, 2004 11:27 PM -0600 Jacob Kjome <ho...@visi.com>
> wrote:
> 
> >>The gist:
> >>
> >>  "In some (most?) cases you cannot use a 'log4j.properties'
> >>   file placed in your web application's WEB-INF/classes
> >>   directory"
> 
> > Who are you quoting?
> 
> Well, myself of course ;-)
> 
> >>...this goes counter to the Log4J's documentation, which says:
> >>
> >>  "The default log4j initialization is particularly useful in web-server
> >>  environments. Under Tomcat 3.x and 4.x, you should place the
> >>  log4j.properties under the WEB-INF/classes directory of your
> >>  web-applications. Log4j will find the properties file and initialize
> >>  itself. This is easy to do and it works."
> 
> > Well, it works fine....as long as you *also* add log4j.jar to WEB-INF/lib.
> > I bet you didn't do that, did you. :-)
> 
> Actually, no.
> 

Actually, yes as you figured out below :-)

> > True, WEB-INF/classes/log4j.properties is irrelevant to
> common/lib/log4j.jar.
> > However, it is *entirely* relevant to WEB-INF/lib/log4j.jar.  Because of
> the
> > class loading behavior of webapps, any webapp with log4j.jar in its own
> > WEB-INF/lib will run its default logger repository in an entirely
> > self-contained environment completely separated from that of the server or
> > other apps.
> 
> Ah...good idea! I didn't think of that. The "greedy" webapp classloader
> will have its own log4j 'universe' (classes *and* logging hierarchy), while
> classloaders higher up the classloader hierarchy are unaffected. You must
> not forget to also add commons-logging jars if you log through
> commons-logging.
> 

Yeah, and avoid commons-logging like the plague if you can!

> Thus, let's summarize:
> 
> Default setup for Tomcat:
> 
>   tomcat4.1.24/common/lib/commons-logging.jar
>   tomcat4.1.24/common/lib/commons-logging-api.jar
>   tomcat4.1.24/common/lib/log4j.jar
>   tomcat4.1.24/common/classes/log4j.properties
> 

I haven't looked at Tomcat-4.1.xx for a while, but does it come with both
commons-logging-api.jar and commons-logging.jar in common/lib? 
commons-logging-api.jar is just commons-logging.jar without log4j support. 
Don't ask me why they separated things, but I think it was to get around weird
classloader issues in Tomcat...caused by none other than commons-logging. 
Tomcat5 doesn't even include commons-logging at all in common/lib.  And the
log4j stuff certainly wasn't there by default since Tomcat doesn't ship with
it....or did you mean that should be the default setup for you, not what it
ships with?

> Setup for webapp using commons-logging with log4j underneath:
> 
>   my_webapp/WEB-INF/lib/commons-logging.jar
>   my_webapp/WEB-INF/lib/commons-logging-api.jar
>   my_webapp/WEB-INF/lib/log4j.jar
>   my_webapp/WEB-INF/classes/log4j.properties
> 

You only need commons-logging.jar, not common-logging-api.jar.  Otherwise, this
is correct.

> Once Tomcat starts up, commons-logging and log4j initialization (if any)
> will be done through the Common classloader and the log4j.properties
> file accessible to the common classloader. All classes loaded from the
> Shared, Catalina and Common classloaders will 'see' that setup.
> 

yep.

> Once the webapp starts up, the Webapp classloader (greedy) will
> restart its own initialization of commons-logging and log4j as these
> classes are directly available to it. It will use the log4j.properties
> file in its classes subdirectory. All classes loaded by the Webapp
> classloader will 'see' that setup.
> 

yep.  Except it doesn't "restart", it just starts.


> Classloader reference:
> 
>        Bootstrap
>            |
>         System
>            |
>            |
>         Common
>          /  \
>         /    \
>        /      \
>    Catalina    |
>             Shared
>               / \
>              /   \
>        Webapp1  Webapp2
> 
> > Jake
> 
> Thanks Jake.
> 

No problem.

> David.
> 
> P.S. But shouldn't there be a notice in the log4j documentation?
> 
> 

I think there is, but I haven't checked lately.  There is other reading linked
to by the Log4j site that points at some articles by Ceki which you can treat as
Log4j documentation.  I think it is mentioned there.

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org