users@glassfish.java.net

AW: logging best practice

From: <w.rittmeyer_at_jsptutorial.org>
Date: Tue, 19 Dec 2006 16:53:21 +0100

>I'm trying to deploy a WAR that includes log4j in the WEB-INF/lib.
>GlassFish isn't finding it, and I understand from reading some of the
>blogs that this is because commons-logging is getting loaded by the
>System classloader is trying to instantiate the log4j classes that are
>on the local Web classloader.


I am a bit troubled here. From within ejb and web-projects. But I use commons-logging as an additional layer. So this might be the difference. Therefore I have both commons-loggin.jar and log4j.jar in my WEB-INF/lib directory. My log4j.properties is within WEB-INF/classes.


>First question: I don't really understand this behavior. Is GlassFish
>autodetecting the use of Log4J in my webapp and trying to load the Log4J
>classes directly from the System classloader rather than from my Web
>classloader? If so, why is it designed that way? Why not just let my
>Web app. load the Log4J classes?
>
>Second question: What is best practice for logging in a Web app that is
>going to be deployed to GlassFish? I don't really like the solution of
>putting Log4J into the GlassFish/lib because I'd like my apps to run on
>an "out of the box" GlassFish (or SJSAS) install. And what if I've got
>different apps using different versions of Log4J?

I think - though others might prove me wrong - that this should be no problem. As long as you deploy all appropriate libraries in your WEB-INF/lib directory.

BTW: I've just tested removing commons-logging.jar from the WEB-INF/lib directory and created a logger using the log4j way in a small test project of mine. And it has worked just fine. But my ejb projects still uses commons-logging. So maybe this can explain the difference.

Do you create your logger using commons-logging LogFactory or log4j LogManager? Using the former without deploying commons-logging could cause the problem.


Hope this helps,

Wolfram



>
>Thanks for any advice,
>
>Mark