You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dave Hoffer <DH...@xrite.com> on 2006/03/28 04:05:51 UTC

[logging] How to get log4j to work with commons-logging in web service app?

I'm not sure if this is a commons-logging or log4j issue but my problem
is that...
 
I have an application (local web service) that uses Jetty and AXIS.  We
just started using commons-logging and we want to configure it to use
log4j.
 
Form the online docs I gathered that to configure commons-logging I
really just had to make sure that log4j was in my classpath; which I did
and through our IDE debugger and I see the following message which, I
think, means that commons-logging found log4j.  (Since this is through
the IDE it is the simple case, i.e. no Jetty and AXIS yet. 
 
log4j:WARN No appenders could be found for logger (Logger_Name).
log4j:WARN Please initialize the log4j system properly.
 
However, when I run the application (fire up Jetty/AXIS/App) I get NO
logging.  I don't know if this is a commons-logging or log4j issue at
runtime as I see nothing.  
 
Do I need any commons-logging property/config file?  If so, where does
it go?
 
I know I will need a log4j.properties file, where should this be
located?  I haven't used log4j much, but I think it has been found in
the current directory before; now this is not working.  I have also put
it in the classpath with no success.
 
Any ideas?  How can I debug to see where the failure is?
 
Thanks.
 
-Dave

 

 

 


Re: [logging] How to get log4j to work with commons-logging in web service app?

Posted by Simon Kitching <sk...@apache.org>.
On Mon, 2006-03-27 at 21:05 -0500, Dave Hoffer wrote:
> I'm not sure if this is a commons-logging or log4j issue but my problem
> is that...
>  
> I have an application (local web service) that uses Jetty and AXIS.  We
> just started using commons-logging and we want to configure it to use
> log4j.
>  
> Form the online docs I gathered that to configure commons-logging I
> really just had to make sure that log4j was in my classpath; which I did
> and through our IDE debugger and I see the following message which, I
> think, means that commons-logging found log4j.  (Since this is through
> the IDE it is the simple case, i.e. no Jetty and AXIS yet. 
>  
> log4j:WARN No appenders could be found for logger (Logger_Name).
> log4j:WARN Please initialize the log4j system properly.

Yep. That means commons-logging found log4j, and log4j couldn't find a
config file.

>  
> However, when I run the application (fire up Jetty/AXIS/App) I get NO
> logging.  I don't know if this is a commons-logging or log4j issue at
> runtime as I see nothing.  
>  
> Do I need any commons-logging property/config file?  If so, where does
> it go?

Well, even though commons-logging does auto-detect logging libs, it's
generally recommended to explicitly specify one. You can do this by
placing a file named "commons-logging.properties" in the classpath
containing:
 org.apache.commons.logging.Log=\
   org.apache.commons.logging.impl.Log4JLogger

or by specifying:
 java -Dorg.apache.commons.log=\
   org.apache.commons.logging.impl.Log4JLogger


>  
> I know I will need a log4j.properties file, where should this be
> located?  I haven't used log4j much, but I think it has been found in
> the current directory before; now this is not working.  I have also put
> it in the classpath with no success.

The log4j file does just need to be in the classpath. However with
containers the problem is that there are multiple "classpaths" floating
around :-(

I recommend including the log4j jarfile with your webapp rather than
relying on one present in a shared dir. I expect log4j only sees config
files visible via the same classloader that loaded the jarfile.

One possibility is that commons-logging is connecting file to log4j, but
that log4j is picking up a config file from somewhere in the container
path. Again, deploying log4j in your webapp should fix that. Otherwise,
perhaps searching for log4j.properties or log4j.xml files might reveal
one..

>  
> Any ideas?  How can I debug to see where the failure is?

If you are using commons-logging 1.1-RC1 or later, then there is a
diagnostic feature you can enable (see release notes). However for
earlier releases there is no easy way of seeing exactly what's
happening.

Regards,

Simon


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


Re: [logging] How to get log4j to work with commons-logging in web service app?

Posted by Boris Unckel <bo...@gmx.net>.
> Von: "Dave Hoffer" <DH...@xrite.com>
> 
> I'm not sure if this is a commons-logging or log4j issue but my problem
> is that...
It is a log4j issue, and you should read
http://www.catb.org/~esr/faqs/smart-questions.html
as all your questions are documented in manuals, see links below.
>  
> log4j:WARN No appenders could be found for logger (Logger_Name).
> log4j:WARN Please initialize the log4j system properly.
>  
> Do I need any commons-logging property/config file?  If so, where does
> it go?
No, but it is easier to find errors if you specify the property.
System property
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
>  
> I know I will need a log4j.properties file, where should this be
> located?  I haven't used log4j much, but I think it has been found in
> the current directory before; now this is not working.  I have also put
> it in the classpath with no success.
Two possibilities:
System property
log4j.configuration=file:///opt/config/log4j.properties
or create a file called log4j.properties and save it into common/classes.
RTFM:
http://tomcat.apache.org/tomcat-5.5-doc/logging.html
http://logging.apache.org/log4j/docs/manual.html
http://jakarta.apache.org/commons/logging/guide.html
http://jakarta.apache.org/commons/logging/troubleshooting.html

Regards
Boris

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