You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Delbecq <de...@oma.be> on 2006/09/05 10:46:07 UTC

logging does not work in my webapp

Hello,
using tomcat, the logging does not work in my webapp. I am out of idea,
so if someone can suggest me something more to test to get my logs.
Here is the situation.
I followed instructions on ow to setup tomcat for log4j (that is
basically adds the commons-logging and log4j jars in common/lib)
I setup a log4j.xml file in my WEB-INF/classes/log4j.xml. I know it's
read by log4j and used by commons-logging, because when i change the
root debug level, it alters the verbosity of struts, bean utils, and so
on. Setting up a org.apache category to reduce verbosity to info only
does work too.

In my custom class i do this:

    private static Log log =
LogFactory.getLog(SharkEngineBean.class.getName()); 
/*be.dissco.shark.jsf.bean.SharkEngineBean*/

......
in a instance method of the class, i have
        log.debug("test");
        log.warn("test");
        log.error("test");
        log.fatal("test");
        System.out.println("You should see error messages above");
I should get log lines on a regular basis, ranging from debug to fatal
levels. However, i get strictly nothing. Anyone can suggest me where to
look for some reason for this to not work. (Btw, i tested,
log.isDebugEnabled() -> log.isFatalEnabled() all return true)

I deploy this and try. I get this in catalina.out
2553 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Scanning web.xml for
controller servlet mapping
2559 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Process servletName=faces,
urlPattern=*.faces
2560 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Process servletName=struts,
urlPattern=*.do
2560 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Process servletName=sharkView,
urlPattern=/processStatus.png
2560 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Mapping for servlet 'struts' =
'*.do'
2560 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Initializing module path ''
configuration from '/WEB-INF/struts-config.xml'
2746 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Initializing module path ''
message resources from 'shark-struts'
2746 [http-8080-Processor1] DEBUG
org.apache.struts.util.PropertyMessageResources  - Initializing,
config='shark-struts', returnNull=true
2746 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Initializing module path ''
data sources
2747 [http-8080-Processor1] DEBUG
org.apache.struts.action.ActionServlet  - Initializing module path ''
plug ins
You should see error messages above
You should see error messages above
You should see error messages above
You should see error messages above
You should see error messages above
You should see error messages above
You should see error messages above
You should see error messages above

As you can see, despite struts and other libs usin  commons-logging
output well, there is no output from my own class. Here is content of
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false" threshold="debug">
    <appender name="A1" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x
- %m%n"/>
        </layout>
    </appender>

    <category name="org.apache.commons.digester">
        <level value="INFO"/>
    </category>
    <category name="org.apache.commons.beanutils">
        <level value="INFO"/>
    </category>
    <category name="be.dissco">
        <level value="DEBUG"/>
    </category>
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="A1"/>
    </root>
</log4j:configuration>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: logging does not work in my webapp

Posted by David Delbecq <de...@oma.be>.
Thanks for this clarification :)
Boris Unckel a écrit :
> Hi,
>
> -------- Original-Nachricht --------
> Datum: Tue, 05 Sep 2006 11:50:34 +0200
> Von: David Delbecq <de...@oma.be>
> An: Tomcat Users List <us...@tomcat.apache.org>
> Betreff: Re: logging does not work in my webapp
>
>   
>> First, problem solved. It appear a 3rd party library include in my
>> webapp was doing a manual configuration of log4j, resetting the root
>> logger and sending logs to some file in the middle of nowhere.
>>     
> OK, so something completely different.
>   
>> Thanks for information. Am just curious, you tell me to put my
>> commons-logging and log4j in my webapp (that's what i was doing before
>> reading docs). However, if i read well the docs (tomcat 5.5) on
>> classloader, the commons-logging in tomcat/bin will take precedence
>> because it's a system class and as such can not be overwritten by the
>> webapp ////$CATALINA_HOME/bin/commons-logging-api.jar is in system
>> classloader. //
>>     
> ....
>   
>> May the doc be wrong about it? could my commons-logging in webapp take
>> precedence of the one in tomcat?
>> //
>>
>>     
> You are right, it is documented at
> http://jakarta.apache.org/commons/logging/commons-logging-1.1/troubleshooting.html#Containers_With_Custom_ClassLoading_Behaviour_for_Logging
> but JCL is classloader-aware, especially 1.1 has been closely tested into that direction. If you have commons-logging-api.jar (1.1) in you TOMCAT_ROOT/bin and commons-logging.jar in WEB-INF/lib and additionally the library of your choice (in your case: log4j) in WEB-INF/lib, commons-logging will detect that and choose the correct library.
> If you have it in commons/lib any webapp will use log4j with the configuration "found first" (random) if there is more than one.
>
> Regards
> Boris
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: logging does not work in my webapp

Posted by Boris Unckel <bo...@gmx.net>.
Hi,

-------- Original-Nachricht --------
Datum: Tue, 05 Sep 2006 11:50:34 +0200
Von: David Delbecq <de...@oma.be>
An: Tomcat Users List <us...@tomcat.apache.org>
Betreff: Re: logging does not work in my webapp

> First, problem solved. It appear a 3rd party library include in my
> webapp was doing a manual configuration of log4j, resetting the root
> logger and sending logs to some file in the middle of nowhere.
OK, so something completely different.
> 
> Thanks for information. Am just curious, you tell me to put my
> commons-logging and log4j in my webapp (that's what i was doing before
> reading docs). However, if i read well the docs (tomcat 5.5) on
> classloader, the commons-logging in tomcat/bin will take precedence
> because it's a system class and as such can not be overwritten by the
> webapp ////$CATALINA_HOME/bin/commons-logging-api.jar is in system
> classloader. //
....
> 
> May the doc be wrong about it? could my commons-logging in webapp take
> precedence of the one in tomcat?
> //
> 
You are right, it is documented at
http://jakarta.apache.org/commons/logging/commons-logging-1.1/troubleshooting.html#Containers_With_Custom_ClassLoading_Behaviour_for_Logging
but JCL is classloader-aware, especially 1.1 has been closely tested into that direction. If you have commons-logging-api.jar (1.1) in you TOMCAT_ROOT/bin and commons-logging.jar in WEB-INF/lib and additionally the library of your choice (in your case: log4j) in WEB-INF/lib, commons-logging will detect that and choose the correct library.
If you have it in commons/lib any webapp will use log4j with the configuration "found first" (random) if there is more than one.

Regards
Boris

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: logging does not work in my webapp

Posted by David Delbecq <de...@oma.be>.
First, problem solved. It appear a 3rd party library include in my
webapp was doing a manual configuration of log4j, resetting the root
logger and sending logs to some file in the middle of nowhere.


Thanks for information. Am just curious, you tell me to put my
commons-logging and log4j in my webapp (that's what i was doing before
reading docs). However, if i read well the docs (tomcat 5.5) on
classloader, the commons-logging in tomcat/bin will take precedence
because it's a system class and as such can not be overwritten by the
webapp ////$CATALINA_HOME/bin/commons-logging-api.jar is in system
classloader. //

Therefore, from the perspective of a web application, class or resource
loading looks in the following repositories, in this order:

    * Bootstrap classes of your JVM
    * System class loader classses (described above)
    * //WEB-INF/classes/ of your web application
    * //WEB-INF/lib/*.jar/ of your web application
    * /$CATALINA_HOME/common/classes/
    * /$CATALINA_HOME/common/endorsed/*.jar/
    * /$CATALINA_HOME/common/i18n/*.jar/
    * /$CATALINA_HOME/common/lib/*.jar/
    * /$CATALINA_BASE/shared/classes/
    * /$CATALINA_BASE/shared/lib/*.jar/

May the doc be wrong about it? could my commons-logging in webapp take
precedence of the one in tomcat?
//

Boris Unckel a écrit :
> Hello David,
>
> my answers are inline:
> -------- Original-Nachricht --------
> Datum: Tue, 05 Sep 2006 10:46:07 +0200
> Von: David Delbecq <de...@oma.be>
> An: users@tomcat.apache.org
> Betreff: logging does not work in my webapp
>
>   
>> Hello,
>> using tomcat, the logging does not work in my webapp. I am out of idea,
>> so if someone can suggest me something more to test to get my logs.
>> Here is the situation.
>> I followed instructions on ow to setup tomcat for log4j (that is
>> basically adds the commons-logging and log4j jars in common/lib)
>>     
> I think you are referring to
> http://tomcat.apache.org/tomcat-5.5-doc/logging.html
> which assumes you are using Tomcat 5.5.
> >From the text:
> "Your web applications should certainly use their own log4j configuration. This is valid with the above configuration. You would place a similar log4j.properties file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j which does *not* require Commons-Logging, and you should consult the log4j documentation for more options. This page is intended only as a bootstrapping guide."
>
> In other words:
> Avoid to put commons-logging and log4j in commons/lib
> and put everything in WEB-INF/lib.
>
> Replace the default commons-logging-api.jar in TOMCAT_HOME/bin with the current version 1.1 and have a look at the diagnostic function
> http://jakarta.apache.org/commons/logging/commons-logging-1.1/troubleshooting.html#Using_JCL_Diagnostics
> Both jars (commons-logging-api.jar and commons-logging.jar should have the same version).
>
>   
>> I setup a log4j.xml file in my WEB-INF/classes/log4j.xml. I know it's
>> read by log4j and used by commons-logging, because when i change the
>> root debug level, it alters the verbosity of struts, bean utils, and so
>> on. Setting up a org.apache category to reduce verbosity to info only
>> does work too.
>>
>> In my custom class i do this:
>>
>>     private static Log log =
>> LogFactory.getLog(SharkEngineBean.class.getName()); 
>> /*be.dissco.shark.jsf.bean.SharkEngineBean*/
>>     
> The use of a static Log is bad practise. Have a look at:
> http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>
> Regards
> Boris
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: logging does not work in my webapp

Posted by Boris Unckel <bo...@gmx.net>.
Hello David,

my answers are inline:
-------- Original-Nachricht --------
Datum: Tue, 05 Sep 2006 10:46:07 +0200
Von: David Delbecq <de...@oma.be>
An: users@tomcat.apache.org
Betreff: logging does not work in my webapp

> Hello,
> using tomcat, the logging does not work in my webapp. I am out of idea,
> so if someone can suggest me something more to test to get my logs.
> Here is the situation.
> I followed instructions on ow to setup tomcat for log4j (that is
> basically adds the commons-logging and log4j jars in common/lib)
I think you are referring to
http://tomcat.apache.org/tomcat-5.5-doc/logging.html
which assumes you are using Tomcat 5.5.
>From the text:
"Your web applications should certainly use their own log4j configuration. This is valid with the above configuration. You would place a similar log4j.properties file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j which does *not* require Commons-Logging, and you should consult the log4j documentation for more options. This page is intended only as a bootstrapping guide."

In other words:
Avoid to put commons-logging and log4j in commons/lib
and put everything in WEB-INF/lib.

Replace the default commons-logging-api.jar in TOMCAT_HOME/bin with the current version 1.1 and have a look at the diagnostic function
http://jakarta.apache.org/commons/logging/commons-logging-1.1/troubleshooting.html#Using_JCL_Diagnostics
Both jars (commons-logging-api.jar and commons-logging.jar should have the same version).

> I setup a log4j.xml file in my WEB-INF/classes/log4j.xml. I know it's
> read by log4j and used by commons-logging, because when i change the
> root debug level, it alters the verbosity of struts, bean utils, and so
> on. Setting up a org.apache category to reduce verbosity to info only
> does work too.
> 
> In my custom class i do this:
> 
>     private static Log log =
> LogFactory.getLog(SharkEngineBean.class.getName()); 
> /*be.dissco.shark.jsf.bean.SharkEngineBean*/
The use of a static Log is bad practise. Have a look at:
http://wiki.apache.org/jakarta-commons/Logging/StaticLog

Regards
Boris

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org