tag:blogger.com,1999:blog-637417304187784899.post4801137730289795131..comments2024-01-04T09:04:42.121+00:00Comments on James Strachan's Blog: better stack traces in Java with log4j - including the jar file and version number!James Strachanhttp://www.blogger.com/profile/12591119339035350067noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-637417304187784899.post-51311682242612636942008-09-05T11:23:00.000+00:002008-09-05T11:23:00.000+00:00James, great work yet again.Love the lateral on th...James, great work yet again.<BR/><BR/>Love the lateral on that one. Many times I have hunted an issue where this would have helped.<BR/><BR/>nice.Ramonhttps://www.blogger.com/profile/09716695225909554060noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-12227902955376542402008-09-02T18:44:00.000+00:002008-09-02T18:44:00.000+00:00By the way I think we need to abandon logging. Sor...By the way I think we need to abandon logging. Sorry. <BR/><BR/>It has served it purposes but we need to move beyond the dark ages and consider having a proper diagnostics API as well as dynamic runtime configuration management model that can describe the state pertinent to many different software execution aspects. <BR/><BR/>Dumping stack traces to a log file is simply wasteful and unproductive when the light shines.Unknownhttps://www.blogger.com/profile/00414063535114178838noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-59470947076897642132008-09-02T18:36:00.000+00:002008-09-02T18:36:00.000+00:00williamlouth.wordpress.com is a new blog.I am just...williamlouth.wordpress.com is a new blog.<BR/><BR/>I am just preparing the entry but I can tell you that there is no way of doing this from within the Java runtime itself in an efficient and correct manner. You have to go native. But at least it is possible and it can work with Java 1.2+ runtimes and on all major OS platforms.<BR/><BR/>StackTraceElement was a design mistake especially as developers are already so comfortable with java.lang.reflect.Method.Unknownhttps://www.blogger.com/profile/00414063535114178838noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-370179086970395562008-09-02T16:51:00.000+00:002008-09-02T16:51:00.000+00:00William Louth:The findClass(String) method as impl...William Louth:<BR/><BR/>The findClass(String) method as implemented by James is not guaranteed to get the correct results, especially if the class in question can be found in multiple classloaders that James searches. I think that there is no way to determine with certainty which classloader loaded the class in question given its name (the class' name). AFAIK, only the name of the class is available in StackTraceElement, not the actual class. <BR/><BR/>There are ways to alleviate this problem. See the logback project,<BR/>and in particular http://jira.qos.ch/browse/LBGENERAL-23 for more details.Cekihttps://www.blogger.com/profile/06948108407442025539noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-47451012061469771952008-09-02T15:27:00.000+00:002008-09-02T15:27:00.000+00:00am wondering if this is your blog William?am wondering if <A HREF="http://williamlouth.wordpress.com/" REL="nofollow">this is your blog William</A>?James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-58385270414230638682008-09-02T15:25:00.000+00:002008-09-02T15:25:00.000+00:00William - could you post your blog URL here when y...William - could you post your blog URL here when you've posted it, so we can see it?James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-66000151711713785962008-09-02T15:23:00.000+00:002008-09-02T15:23:00.000+00:00Am looking forward to hearing your solution :)I di...Am looking forward to hearing your solution :)<BR/><BR/>I didn't realise there were any anti-commercial software or logging fanatics reading my blog comments. I'll keep on the look out for them & try keep them off your back if they do show up! :)James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-83025168423135792252008-09-02T15:03:00.000+00:002008-09-02T15:03:00.000+00:00Yes I do have a solution. I will post it on my blo...Yes I do have a solution. I will post it on my blog later as I do not want to get abushed by anti-commercial software and/or logging fanatics. <BR/><BR/>I just thought I would at least draw attention to the issue which should be noted in the patch (if it is not already).Unknownhttps://www.blogger.com/profile/00414063535114178838noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-56987312949763497392008-09-02T14:55:00.000+00:002008-09-02T14:55:00.000+00:00William - unfortunately the JVM's StackTrace doesn...William - unfortunately the JVM's StackTrace doesn't expose the actual Class objects which would make the patch pretty trivial. Given the plenthora of different class loader tricks that take place, its the best attempt at finding the class that caused the exception from the stack trace I could think of - typically the thread context class loader is gonna be the active one in most app servers for example.<BR/><BR/>There's a risk though - it might not be the correct class loader in all cases - but in most cases it should be. (Its certainly better from giving no versioning information ever for any stack trace! :).<BR/><BR/>Do you have a better way this could be done?James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-36670322188401444222008-09-02T14:52:00.000+00:002008-09-02T14:52:00.000+00:00James are you saying that the following method in ...James are you saying that the following method in the patch accurately determines the class for a method on the callstack? Yes or No?<BR/><BR/>William<BR/><BR/>private Class findClass(String className) {<BR/>+ try {<BR/>+ return Thread.currentThread().getContextClassLoader().loadClass(className);<BR/>+ } catch (ClassNotFoundException e) {<BR/>+ try {<BR/>+ return Class.forName(className);<BR/>+ } catch (ClassNotFoundException e1) {<BR/>+ try {<BR/>+ return getClass().getClassLoader().loadClass(className);<BR/>+ } catch (ClassNotFoundException e2) {<BR/>+ return null;<BR/>+ }<BR/>+ }<BR/>+ }<BR/>+ }Unknownhttps://www.blogger.com/profile/00414063535114178838noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-24199071058427177652008-09-02T14:03:00.000+00:002008-09-02T14:03:00.000+00:00Have attached another patch that makes it configur...Have attached <A HREF="https://issues.apache.org/bugzilla/show_bug.cgi?id=45721" REL="nofollow">another patch</A> that makes it configurable :)James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-53344449369749364702008-09-02T12:41:00.000+00:002008-09-02T12:41:00.000+00:00Very cool patch. Very sharp thinking on your part...Very cool patch. Very sharp thinking on your part. Amazing no one did this before.<BR/><BR/>I do agree with the commenter on the bug though that it would be nice to be configurable.<BR/><BR/>But I will definitely keep this patch handy.Unknownhttps://www.blogger.com/profile/01271389641643601778noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-42069378582274717752008-09-02T08:10:00.000+00:002008-09-02T08:10:00.000+00:00Ceki - you're right; if folks don't put the versio...Ceki - you're right; if folks don't put the version in the jar name or in the manifest, this patch won't help. <BR/><BR/>However it will work for all jars created via Maven or hosted in a maven repository today (which is quite a large amount of java code) - plus its a great encouragement to anyone using Ant or Eclipse to start filling in that manifest - or including the version number in the jar.<BR/><BR/>Jon - there's no real reason that the JVM itself can't include this in stack traces; I just figured getting a JVM change in might take a long time :) In the meantime its trivial to take the patch and use it in any Java project; basically whenever a stack trace is created, we can generate a nice versioned stack trace. <BR/><BR/>Maybe its worth spinning up the code in a little project on google code so folks can easily embed the same feature inside their apps if they like - though I figured including it in the various logging frameworks was probably the simplest route which given how prolific the various logging libraries are - would generally not introduce a new dependency.<BR/><BR/>Thanks everyone for your comments!James Strachanhttps://www.blogger.com/profile/12591119339035350067noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-40402496924676403762008-09-02T05:54:00.000+00:002008-09-02T05:54:00.000+00:00OMG, this is the solution to classloader issues! B...OMG, this is the solution to classloader issues! Brilliant! Now, this will be even more brilliant if it could somehow work without needing to patch log4j. =)ahttps://www.blogger.com/profile/11867559494404858630noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-27168833593245625122008-09-02T04:08:00.000+00:002008-09-02T04:08:00.000+00:00I am puzzled why this hasn't been added for 3-5 ye...I am puzzled why this hasn't been added for 3-5 years ago? But very helpful. +1 to get it in log4j.<BR/><BR/>What about OSGi bundles? Any help there to get the version also?Claus Ibsenhttps://www.blogger.com/profile/17434564836989249540noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-17795866787963614452008-09-01T23:52:00.000+00:002008-09-01T23:52:00.000+00:00It's things like this that will get Implementation...It's things like this that will get ImplementationVersion set though :) Hoping it gets in log4j.Unknownhttps://www.blogger.com/profile/17959856174272222057noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-46092024649496485652008-09-01T19:15:00.000+00:002008-09-01T19:15:00.000+00:00Assuming the version number is the more valuable i...Assuming the version number is the more valuable information, the patch works if either the "ImplementationVersion" is set in the manifest, or if the jar file name includes a version suffix. ImplementationVersion is rarely set and most jars do not have a version suffix, unless they are from a Maven repository. <BR/><BR/>I have the nagging feeling that extracting the version data will not always work, even if the general idea is pretty brilliant.Cekihttps://www.blogger.com/profile/06948108407442025539noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-20419916745774785922008-09-01T18:42:00.000+00:002008-09-01T18:42:00.000+00:00Brilliant!Brilliant!Unknownhttps://www.blogger.com/profile/11007414545203978127noreply@blogger.comtag:blogger.com,1999:blog-637417304187784899.post-40180269320463616752008-09-01T15:01:00.000+00:002008-09-01T15:01:00.000+00:00Hi James, cool!BR,~AHi James,<BR/><BR/> cool!<BR/><BR/>BR,<BR/>~AAnjanBacchuDevhttps://www.blogger.com/profile/09418545608553510487noreply@blogger.com