You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2007/02/10 00:50:24 UTC

Exception logging

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

I've been using struts for several years at this point, and the "right"
way to do error processing has always eluded me. I have web.xml
configured to display nice error pages instead of barfing everywhere
with a stack trace. I have it pointing to a velocity template that is
fairly simple and I feel like I can rely on that not to fail.

On the other hand, I'd like to log exceptions to a logfile of my
choosing which pretty much means that I need have some of *my* code run,
which could potentially fail, sending me into a nasty exception
processing loop.

Struts itself provides for <exception> elements in struts-config.xml,
which I'm looking into. The documentation in the DTD says that the
default exception handler is action.ExceptionHandler, which basically
just logs the exception using commons-logging.

This ought to be enough for my needs, but I have two questions:

1. Is action.ExceptionHandler set up by default for all exceptions
   if I don't specify any <exception> elements anywhere in my
   config?

2. Why do I need to provide values for attributes such as "key",
   in order to use the default handler?

I'm already using log4j with my application and that's the perfect place
for exceptionsHowever, the log messages end up in catalina.out (I'm
using Tomcat 5.5). It seems obvious that I simply need to properly
configure commons-logging to hook up with my already-configured log4j
and everything will be fine.

I've read the logging section of the Struts User's Guide
(http://struts.apache.org/1.3.5/userGuide/configuration.html#config_logging)
which refers the user to another section
(http://struts.apache.org/1.3.5/userGuide/building_controller.html#logging),
which does not give instructions for getting commons-logging hooked-up
to log4j.

I package log4j with my application, so the JAR file is in WEB-INF/lib.
I'm mentioning that because I realize that loggers are sensitive to
their classloader, and commons-logging is being provided by Tomcat at a
higher level.

So, I could really use some general advice in terms of the best approach
to just log my darned exceptions, and then, assuming that simply getting
commons-logging to use log4j as its logger is the solution, I could use
some help getting that working.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFzQjA9CaO5/Lv0PARAhEJAJ9gXFRqecrHd7FekPbdDHz/mam66wCgpueF
U9DK25oVF9xXrjd1RPRMAuA=
=Pv9o
-----END PGP SIGNATURE-----

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