[EMAIL PROTECTED] wrote:

> I've just started using Log4j in Tomcat.  Using BasicConfigurator, all my
> Log4j messages stream to the Tomcat console.

which version of tomcat are you using? i use tomcat 4, and all my stdout
logging goes to catalina.out.

> How do I make them go to the log?

i'm a log4j newbie but the attached custom appender works for me.
if you want to use it, then one way is to call from you servlet passing in
the context

Category.getRoot().addAppender(new ContextLogAppender(context));

if you want to use layout x, you need to set it before adding the appender

ContextLogAppender app=new ContextLogAppender(context);
app.setLayout(x);
Category.getRoot().addAppender(app);

> Is there a servlet log appender that send trace commands to the
> ServletContext.log method or the GenericServlet.log method?
> Or is there some other way I should be doing this?

that's a question that i'd like to know the answer to as well!

- robert
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class ContextLogAppender extends org.apache.log4j.AppenderSkeleton
{
    private ServletContext context=null;
    
    public ContextLogAppender(ServletContext c)
    {
        this.context=c;
        log("Started log.");    
    }

    public boolean requiresLayout()
    {
        return false;
    }

      protected void append(LoggingEvent event)
    {
        log(event.message);    
    }

        protected void log(String message)     
    {
        if (context != null)
        {
                context.log("ContextLogAppender: " + message);
        } else {
                System.out.println("ContextLogAppender: " + message);
        }
        }
    
    public void close()
    {
        log("Closed log.");
    }
}





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to