> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> I usually do what Yoav described.
Me too.
We used the following guidelines to cleanup our logging mess. We had
things being logged multiple times etc. This among other things is
what actually got me interested in log4j. We now have a pretty good
looking log.
1) If you swallow an Exception, Log it.
} catch (Exception e) {
log.error(e);
}
2) Unless, the exception is about to go across the wire. Then Log it,
and rethrow it. [This became easier in JMX as we created an invoker,
at the container level which if it saw an exception, logged it. So
this rule was actually able to be collapsed into #4.]
} catch (Exception e) {
log.error(e);
throw e;
}
3) If you create a new Exception, use the constructor which accepts a
cause. (That is pass the caught exception in as an argument to the
new Exception.)
} catch (Exception cause) {
throw new FooBarException(otherStuff, cause);
}
Note: Do not embed the causing Exception's message text in the
message of your new Exception. Instead, just use the cause when
you create the new Exception. Later all the Exception's messages
will print out. [We wrote an Iterator used in a subclass of Logger
to traverse the whole Exception graph (including SQLExceptions,
MBeanException, etc.) and log the message from each exception,
and the stacktrace from the root cause. This assumes JDK 1.4+.]
4) If after removing the logging, all the code does is rethrow the
Exception. Don't bother catching it.
} catch (Exception e) {
throw e;
}
Delete the catch block entirely, and let the exception propagate up.
Mike Rieser
Test all things; hold fast to that which is good. - 1 Thessalonians 5:21
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]