Re: Column numbers in stack trace - enhancement request
java.util.logging
org.apache.log4j
Sasi wrote:
Lew,
Could you explain how java.util.logging or Log4J can help here? I went
through their docs a little bit, but I couldn't find a way to figure
out how they can help in the problem we are discussing.
Sure! You raised several needs, such as
if the trace contains what method call was attempted on
the null variable, it might help differentiate many of the cases where
the return types of two methods in the same line are identical. JRE
should be able to provide the method name, shouldn't it?
The logging packages give the programmer explicit control over this behavior
and others that you described. You need to write an exception handler anyway,
so you including a call to
logger.error( stringContainingAllSortsOfInformation );
in it.
In the log message you can include any useful information available, which at
the point of capture can be pretty darn fine grained.
catch ( NullPointerException exc )
{
String msg = "Variable foo was null in method( foo ). "
+ exc.getMessage();
logger.error( msg );
return FAILURE;
}
The logging mechanism itself will timestamp the entries, provide class and
thread context, and do other useful stuff under the hood.
Including have negligible impact on performance when the logging level is set
high enough.
This does mean writing a whole mess o' catch blocks and if blocks with message
string construction and log calls, but you know what? You have to do that
anyway to achieve "algebraic closure" (metaphorically) of program behavior.
Aspect-oriented programming (AOP) promises at least some relief from the
drudgery involved.
- Lew