You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "James.Strachan" <ja...@gmail.com> on 2008/09/01 14:51:41 UTC

[PATCH] when showing a stack trace - include the relative package versions and optional jar name to aid debugging

When problems occur in open source software users tend to get stack traces.
They often fire them off to some open source mailing list or forum asking
for help; often without providing much in the way of detail. One of the
first questions asked by support teams is often 'OK, what version are you
using'.

Given that its possible to figure out the actual version being used of each
class - either using the package information from the MANIFEST or by finding
the jar the class came from, it seems logical to include the version
information into a stack trace at the end of the line.

One day the JVM might actually do this for us :)

In the meantime, here's a trivial patch which appends an optional String to
stack traces printed with log4j which includes the jar file name if it can
be deduced plus the Java Package version the line of code comes from.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45721

Here's an example...

org.apache.log4j.config.PropertySetterException: Hello
	at
org.apache.log4j.spi.ThrowableInformationTest.testStackTracePackageName(ThrowableInformationTest.java:306)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [1.5.0]
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[1.5.0]
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[1.5.0]
	at java.lang.reflect.Method.invoke(Method.java:585) [1.5.0]
	at junit.framework.TestCase.runTest(TestCase.java:154) [junit-3.8.1.jar]
	at junit.framework.TestCase.runBare(TestCase.java:127) [junit-3.8.1.jar]
	at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit-3.8.1.jar]
	at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit-3.8.1.jar]
	at junit.framework.TestResult.run(TestResult.java:109) [junit-3.8.1.jar]
	at junit.framework.TestCase.run(TestCase.java:118) [junit-3.8.1.jar]
	at junit.textui.TestRunner.doRun(TestRunner.java:116) [junit-3.8.1.jar]
	at
com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:94)
[idea_rt.jar]
	at junit.textui.TestRunner.doRun(TestRunner.java:109) [junit-3.8.1.jar]
	at
com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:22)
[idea_rt.jar]
	at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
[idea_rt.jar]
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
[idea_rt.jar]

So you can see what version of junit is being used (despite there being no
manifest information) along with the JDK implementation version. 

e.g.

  at java.lang.reflect.Method.invoke(Method.java:585) [1.5.0]

means we found the package number but couldn't find the jar file. Whereas 

  at junit.framework.TestCase.run(TestCase.java:118) [junit-3.8.1.jar]

means we found the jar file but the jar file has no manifest version
information.

Thoughts?

James



-- 
View this message in context: http://www.nabble.com/-PATCH--when-showing-a-stack-trace---include-the-relative-package-versions-and-optional-jar-name-to-aid-debugging-tp19254233p19254233.html
Sent from the Log4j - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: [PATCH] when showing a stack trace - include the relative package versions and optional jar name to aid debugging

Posted by "James.Strachan" <ja...@gmail.com>.


Thorbjørn Ravn Andersen wrote:
> 
> James.Strachan skrev  den 01-09-2008 14:51:
>> Thoughts?
>>   
> I really like this :)  Excellent!
> 
> How did you get the idea?
> 

Thanks! :)

I guess the idea just came from frustration at answering a zillion emails
from folks who just post a stack trace without any kind of version or
classpath information, expecting folks to know exactly what caused it - when
the first mail is always 'so what version are you using...' etc :)

I'm more surprised we've not thought of doing something like this before!
Would love to get this patch into the JVM too! :)

James
-- 
View this message in context: http://www.nabble.com/-PATCH--when-showing-a-stack-trace---include-the-relative-package-versions-and-optional-jar-name-to-aid-debugging-tp19254233p19269630.html
Sent from the Log4j - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: [PATCH] when showing a stack trace - include the relative package versions and optional jar name to aid debugging

Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
James.Strachan skrev  den 01-09-2008 14:51:
> Thoughts?
>   
I really like this :)  Excellent!

How did you get the idea?

-- 
  Thorbjørn Ravn Andersen          "... plus... Tubular Bells!"


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org