[Caveat-- I only got this working yesterday, so I may not have everything
exactly right yet.]

Pedro wrote:
> I would like to configure log4j in my tomcat environment. I included a
> log4j.properties in my web application inside WEB-INF/classes/.

Sounds good.

> I put my war (ngincare.war) in webapps and included a <context> 
> for my web application in server.xml with the following lines:
> <context docBase="ngincare.war" debug="9" reloadable="true"
>      path="ngincare">
>    <Logger
>               className="org.apache.catalina.logger.FileLogger"
>               prefix="localhost_ngincare_log."
>               suffix=".txt"
>               timestamp="true" />
> </context>
> But unfortunately my log is still being appended in catalina.out!

AFAIK, this has nothing to do with log4j, but it should have caused the
stuff that the container is logging to go to the file you specified.  But...
shouldn't 'Context' be capitalized?  Not sure if that matters, but since
it's not working, I would capitalize it and try again.

Now, on to log4j:

> My log4j.properties is defined like this:
> log4j.rootLogger=,NGIN
> log4j.category.PT.ptinovacao.ngincare=NGIN
> log4j.appender.NGIN=org.apache.log4j.ConsoleAppender
> log4j.appender.NGIN.layout=org.apache.log4j.PatternLayout
> log4j.appender.NGIN.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
> I don't know if my context is being really used by my web application
> since I never could configure a <resource> element there! The only way I
> could get a resource to work was put it inside the <DefaultContext>
> element!! Could it be?

I haven't done anything with contexts or resources in order to get log4j
working, so I'm not sure if that's another way to do this or if it's just
not necessary.

How are you using this logger?  I'm using commons-logging on top of log4j.
So in my classes, I have:
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
//replace "ClassName" with the actual class name:
private static Log log = LogFactory.getLog( ClassName.class );
//then to write a message:
log.debug( "a debug message" );

When you say it's not working... are you not seeing *any* logging messages,
or seeing them in the wrong format?  I was able to confirm that my
properties file was being used by changing the ConversionPattern and looking
to see if the output changed.

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University PA Information Resources Management

Reply via email to