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
.



Relevant Pages

  • Re: Logging Best Practice?
    ... log "Performing action Y." ... followed by a crash, he can be pretty sure the error is somewhere in the code for action Y. As you pointed out, trying to print this message /after/ action Y is completed doesn't really help the debugging programmer. ... Programs that aren't broken don't need this kind of logging, ... fix a broken program right now? ...
    (comp.programming)
  • Re: [fw-wiz] RE: Help w/ Port 137 Traffic
    ... >Not logging 137/udp is a good idea because it fills up the logs and does ... Reading this thread, I notice something funny. ... Everyone says that logging ... blocked UDP 137 adds no useful information, and I understand where this is ...
    (Firewall-Wizards)
  • Re: [fw-wiz] RE: Help w/ Port 137 Traffic
    ... >Not logging 137/udp is a good idea because it fills up the logs and does ... Reading this thread, I notice something funny. ... Everyone says that logging ... blocked UDP 137 adds no useful information, and I understand where this is ...
    (Firewall-Wizards)
  • Re: Whats wrong with IGS?
    ... tweet wrote: ... anything or get any useful information unless you are logged in. ... merely from a website link, without logging into KGS. ...
    (rec.games.go)
  • Re: File manipulations in Ada.Text_IO
    ... such a race condition, and their customer trips over it once in a while, the programmer might never find out about it. ... After a year of use, there were no reports of conflicts, so I took the logging out. ...
    (comp.lang.ada)