List of usage examples for java.lang StackTraceElement getMethodName
public String getMethodName()
From source file:Main.java
private static String formatStackTraceElement(StackTraceElement ste) { return compressClassName(ste.getClassName()) + "." + ste.getMethodName() + (ste.isNativeMethod() ? "(Native Method)" : (ste.getFileName() != null && ste.getLineNumber() >= 0 ? "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")" : (ste.getFileName() != null ? "(" + ste.getFileName() + ")" : "(Unknown Source)"))); }
From source file:Main.java
public static String dumpStack(Thread t) { StringBuilder sb = new StringBuilder(); sb.append(t.getName() + "[" + t.getId() + "] - " + t.getState() + ":\n"); for (StackTraceElement ste : t.getStackTrace()) { sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")\n"); }//from w w w.j av a 2 s .c o m return sb.toString(); }
From source file:info.magnolia.test.TestUtil.java
public static String getCurrentTestMethodName() { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); for (StackTraceElement ste : stackTrace) { if (ste.getMethodName().startsWith("test")) { return ste.getMethodName(); }/* ww w. j a v a 2 s.c om*/ } throw new IllegalStateException( "Either you're not in a test at all, or you're calling this from a non-jUnit3 test."); }
From source file:Main.java
private static String caller(int i) { StackTraceElement elem = new Throwable().getStackTrace()[i]; return elem.getClassName() + "." + elem.getMethodName(); }
From source file:Main.java
public static String convertStackTraceToString(StackTraceElement[] stackTraceElements) { StringBuilder message = new StringBuilder(); int min = Math.min(stackTraceElements.length, 4); for (int i = 2; i < min; i++) { StackTraceElement element = stackTraceElements[i]; message.append(element.getClassName()).append(": ").append(element.getMethodName()).append("\n"); }//from w w w . j a v a 2s . c om return message.toString(); }
From source file:Main.java
/** * Building Message/*from w ww .ja v a2s .co m*/ * @param msg The message you would like logged. * @return Message String */ protected static String buildMessage(String msg) { StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2]; return caller.getClassName() + "." + caller.getMethodName() + "(): " + msg; }
From source file:x595.Main.java
private static void log(String msg) { try {// ww w . j a v a2 s . c o m throw new Exception(); } catch (Exception e) { StackTraceElement head = e.getStackTrace()[1]; System.out.println("[" + head.getClassName() + "." + head.getMethodName() + "()] > " + msg); } }
From source file:Main.java
public static void debugWhere(String tag, String msg) { Log.d(tag, msg + " --- stack trace begins: "); StackTraceElement elements[] = Thread.currentThread().getStackTrace(); // skip first 3 element, they are not related to the caller for (int i = 3, n = elements.length; i < n; ++i) { StackTraceElement st = elements[i]; String message = String.format(" at %s.%s(%s:%s)", st.getClassName(), st.getMethodName(), st.getFileName(), st.getLineNumber()); Log.d(tag, message);/* w w w . j a v a 2s .c om*/ } Log.d(tag, msg + " --- stack trace ends."); }
From source file:Main.java
protected static void _printThreads(ThreadMXBean bean, long[] ids, StringBuilder sb) { ThreadInfo[] threads = bean.getThreadInfo(ids, 20); for (ThreadInfo info : threads) { if (info == null) continue; sb.append(info.getThreadName()).append(":\n"); StackTraceElement[] stack_trace = info.getStackTrace(); for (StackTraceElement el : stack_trace) { sb.append(" at ").append(el.getClassName()).append(".").append(el.getMethodName()); sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")"); sb.append("\n"); }//from w w w. j ava 2 s. c o m sb.append("\n\n"); } }
From source file:Main.java
public static final String formatStackTrace(final StackTraceElement pStackTraceElement) { return new StringBuilder().append(pStackTraceElement.getClassName()).append('.') .append(pStackTraceElement.getMethodName()).append('(').append(pStackTraceElement.getFileName()) .append(':').append(pStackTraceElement.getLineNumber()).append(')').toString(); }