You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by kranga <kr...@k2d2.org> on 2005/01/11 16:11:16 UTC
Exceoption logging in log4j
How do I get Tapestry to log exceptions using log4j in addition to throwing
them on the screen? I've got log4j.properties and the jar file in the
classpath but it doesn't seem to log there. I know it uses commons logging,
but shouldn't it find log4j and use it? In development, I've got log4j
configured to log to the console. With eclipse I can click on the stack
trace to navigate to the code and I want to take advantage of it.
Thanks
K
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Exceoption logging in log4j
Posted by Bryan Lewis <br...@maine.rr.com>.
You could override activateExceptionPage() in a custom Engine class:
protected void activateExceptionPage(IRequestCycle cycle,
ResponseOutputStream output,
Throwable cause)
throws ServletException
{
// Log the complete trace.
// This will write the details to System.err where log4j will catch
it.
reportException("Activated exception page " + pageName, cause);
try {
cycle.activate("UserFriendlyErrorPage");
renderResponse(cycle, output);
}
catch (Throwable ex) {
// This will happen if something prevents display of the error
// page, like a syntax error in the error page's html.
throw new ServletException(ex.getMessage(), ex);
}
}
The stack trace is written to the log rather than shown to the user. If you
wanted to both log the trace _and_ show the exception page, simply do this
after the reportException():
super.activateExceptionPage(cycle, output, cause);
return;
----- Original Message -----
From: "kranga" <kr...@k2d2.org>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, January 11, 2005 10:20 AM
Subject: Re: Exceoption logging in log4j
>
> Thanks for the basics, but I already have exceptions in my classes! I'm
> talking about exceptions that Tapestry catches and reports on-screen. Is
it
> possible to have Tapestry log those using log4j?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Exceoption logging in log4j
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 11, 2005, at 10:20 AM, kranga wrote:
> Thanks for the basics, but I already have exceptions in my classes! I'm
> talking about exceptions that Tapestry catches and reports on-screen.
> Is it
> possible to have Tapestry log those using log4j?
Yes. Check the Jakarta Commons Logging documentation for how to
configure JCL to use the Log4j implementation (the default is to use
Log4j if it is on the classpath, actually).
I have log4j.properties in WEB-INF/classes and just tried adding this
to it:
log4j.logger.org.apache.tapestry=DEBUG
I got tons of Tapestry DEBUG level messages output after that setting.
Oh, but you want the Exception page to log. If it successfully
displays the Exception page, then nothing gets logged (I don't believe
- at least I don't see it in AbstractEngine.activateExceptionPage). If
you create your own BaseEngine subclass, override
activateExceptionPage, and configure your engine class in .application
you can add logging easily though. In fact, this is exactly what I do
for lucenebook.com. Rather than delegating to super, though, I instead
throw a ServletException to allow the container to catch the error and
go to a custom error.jsp, but you could just call super to get the nice
Tapestry exception page if you like.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Exceoption logging in log4j
Posted by kranga <kr...@k2d2.org>.
Thanks for the basics, but I already have exceptions in my classes! I'm
talking about exceptions that Tapestry catches and reports on-screen. Is it
possible to have Tapestry log those using log4j?
----- Original Message -----
From: "Shing Hing Man" <ma...@yahoo.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, January 11, 2005 10:18 AM
Subject: Re: Exceoption logging in log4j
> > them on the screen? I've got log4j.properties and
> > the jar file in the
> > classpath but it doesn't seem to log there. I know
>
> In addition to above,
> in each java class, you need to have the following
> import statments
>
> import org.apache.log4j.Logger;
> import org.apache.log4j.PropertyConfigurator;
>
> Also add the following line to your Foo Java class,say
> :
> private static Logger log=Logger.getLogger(Foo.class);
>
>
> Shing
>
>
>
> --- kranga <kr...@k2d2.org> wrote:
> > How do I get Tapestry to log exceptions using log4j
> > in addition to throwing
> > them on the screen? I've got log4j.properties and
> > the jar file in the
> > classpath but it doesn't seem to log there. I know
> > it uses commons logging,
> > but shouldn't it find log4j and use it? In
> > development, I've got log4j
> > configured to log to the console. With eclipse I can
> > click on the stack
> > trace to navigate to the code and I want to take
> > advantage of it.
> >
> > Thanks
> > K
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
> >
>
> =====
> Home page :
> http://uk.geocities.com/matmsh/index.html
>
>
>
>
>
> ___________________________________________________________
> ALL-NEW Yahoo! Messenger - all new features - even more fun!
http://uk.messenger.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Exceoption logging in log4j
Posted by Shing Hing Man <ma...@yahoo.com>.
> them on the screen? I've got log4j.properties and
> the jar file in the
> classpath but it doesn't seem to log there. I know
In addition to above,
in each java class, you need to have the following
import statments
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
Also add the following line to your Foo Java class,say
:
private static Logger log=Logger.getLogger(Foo.class);
Shing
--- kranga <kr...@k2d2.org> wrote:
> How do I get Tapestry to log exceptions using log4j
> in addition to throwing
> them on the screen? I've got log4j.properties and
> the jar file in the
> classpath but it doesn't seem to log there. I know
> it uses commons logging,
> but shouldn't it find log4j and use it? In
> development, I've got log4j
> configured to log to the console. With eclipse I can
> click on the stack
> trace to navigate to the code and I want to take
> advantage of it.
>
> Thanks
> K
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
>
=====
Home page :
http://uk.geocities.com/matmsh/index.html
___________________________________________________________
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org