whitlock 2002/10/30 09:43:38 Modified: java/src/org/apache/wsif/logging Trc.java Log: Fix calculation of method names Revision Changes Path 1.9 +39 -23 xml-axis-wsif/java/src/org/apache/wsif/logging/Trc.java Index: Trc.java =================================================================== RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/logging/Trc.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Trc.java 29 Oct 2002 16:52:07 -0000 1.8 +++ Trc.java 30 Oct 2002 17:43:38 -0000 1.9 @@ -1120,22 +1120,23 @@ PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); String stack = sw.getBuffer().toString(); - if (traceTrace) traceLog.debug("TRACE stack="+stack); + + if (traceTrace) + traceLog.debug("TRACE stack=" + stack); // The next while loop tries to find the method that called - // Trc. The method name will have (...parmeters...) after it - // and will be after the last call to Trc. - StringTokenizer st1 = new StringTokenizer(stack); + // Trc. The line with the method name will be after the last + // call to Trc. + StringTokenizer st1 = + new StringTokenizer( + stack, + System.getProperty("line.separator", "\n")); boolean foundWsifLogging = false; - String tok = null; + String tok1 = null; while (st1.hasMoreTokens()) { - tok = st1.nextToken(); - if (traceTrace) traceLog.debug("TRACE token="+tok); - - if (tok.indexOf("(") == -1) - continue; + tok1 = st1.nextToken(); - if (tok.startsWith(wsifPackageName + ".logging")) { + if (tok1.indexOf(wsifPackageName + ".logging") != -1) { foundWsifLogging = true; continue; } @@ -1143,7 +1144,21 @@ if (foundWsifLogging) break; } - if (traceTrace) traceLog.debug("TRACE broken out token="+tok); + if (traceTrace) + traceLog.debug("TRACE token=" + tok1); + + // Now find the first word which contains a (. This should be + // prefixed by the method name. If there isn't a (, which + // is unlikely, use the whole line. + StringTokenizer st2 = new StringTokenizer(tok1); + String tok2 = null; + while (st2.hasMoreTokens()) { + tok2 = st2.nextToken(); + if (tok2.indexOf("(") != -1) + break; + } + if (tok2.indexOf("(") == -1) + tok2 = tok1; // Indent the method name by the number of WSIF calls // higher up the stack. This improves readability. There @@ -1151,17 +1166,18 @@ // but this seemed the most reliable (and simplest). buff.append(" "); while (st1.hasMoreTokens()) { - if (st1.nextToken().startsWith(wsifPackageName)) + if (st1.nextToken().indexOf(wsifPackageName) != -1) buff.append(" "); } // Strip off the (... parameters...). I expect there will // always be a ( in the token, but this code copes even if // there isn't. - int idx = tok.indexOf("("); + int idx = tok2.indexOf("("); if (idx != -1) - tok = tok.substring(0, idx); - if (traceTrace) traceLog.debug("TRACE token="+tok); + tok2 = tok2.substring(0, idx); + if (traceTrace) + traceLog.debug("TRACE token=" + tok2); // Now strip off the WSIF package name off the front of // the class name. All WSIF class names are unique, so @@ -1170,20 +1186,20 @@ // WSIF (unlikely) then output the whole // packagename.classname.methodname. String result = null; - if (tok.startsWith(wsifPackageName)) { - StringTokenizer st2 = new StringTokenizer(tok, "."); + if (tok2.startsWith(wsifPackageName)) { + StringTokenizer st3 = new StringTokenizer(tok2, "."); String previous = null; - while (st2.hasMoreTokens()) { + while (st3.hasMoreTokens()) { previous = result; - result = st2.nextToken(); - if (traceTrace) traceLog.debug("TRACE result="+result); + result = st3.nextToken(); } if (previous != null) result = previous + "." + result; } else - result = tok; + result = tok2; - if (traceTrace) traceLog.debug("TRACE appending result="+result); + if (traceTrace) + traceLog.debug("TRACE appending result=" + result); buff.append(result); }