List of usage examples for java.lang StackTraceElement getMethodName
public String getMethodName()
From source file:com.aotome202.lostjason.e202project.apputils.MLog.java
public static int printMethodName(String TAG) { if (!LOG_OUT) { return -1; }//www. ja va 2 s. co m String msg = ""; StackTraceElement info = LogInfo.getInfoInternal(LENGTH); if (info != null) { msg = info.getMethodName() + " # Line " + info.getLineNumber(); } return Log.i(TAG, msg); }
From source file:org.kuali.kfs.module.tem.web.JstlFunctions.java
/** * Get the stack trace from a <code>{@link Throwable}</code> and create a log message from it for tracing purposes * * @param thrownObj/* www.j a va 2 s. c o m*/ * @return String log message */ private static String buildTraceMessage(Throwable thrownObj) { StackTraceElement stackTraceElement = thrownObj.getStackTrace()[0]; return new StringBuilder(stackTraceElement.getClassName()).append("#") .append(stackTraceElement.getMethodName()).append(":").append(stackTraceElement.getLineNumber()) .append(" ").append(thrownObj.getClass().getSimpleName()).append("\n") .append(thrownObj.getMessage()).toString(); }
From source file:org.apache.tajo.exception.ErrorUtil.java
public static Stacktrace.StackTrace convertStacktrace(Throwable t) { Stacktrace.StackTrace.Builder builder = Stacktrace.StackTrace.newBuilder(); if (t != null) { for (StackTraceElement element : t.getStackTrace()) { builder.addElement(Stacktrace.StackTrace.Element.newBuilder() .setFilename(element.getFileName() == null ? "(Unknown Source)" : element.getFileName()) .setFunction(element.getClassName() + "::" + element.getMethodName()) .setLine(element.getLineNumber())); }/*from www . j a v a 2s. c om*/ } return builder.build(); }
From source file:org.apache.flink.api.java.Utils.java
public static String getCallLocationName(int depth) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); if (stackTrace.length < depth) { return "<unknown>"; }//w w w . j a va 2 s . c o m StackTraceElement elem = stackTrace[depth]; return String.format("%s(%s:%d)", elem.getMethodName(), elem.getFileName(), elem.getLineNumber()); }
From source file:org.kantega.notsoserial.NotSoSerialClassFileTransformer.java
public static void registerDeserialization(String className) { Set<String> deserializingClasses = NotSoSerialClassFileTransformer.deserializingClasses; if (!deserializingClasses.contains(className)) { deserializingClasses.add(className); String prettyName = className.replace('/', '.'); dryRunWriter.println(prettyName); dryRunWriter.flush();//from ww w. j av a 2 s. co m if (traceWriter != null) { traceWriter .println("Deserialization of class " + prettyName + " (on " + new Date().toString() + ")"); boolean foundReadObject = false; for (StackTraceElement element : Thread.currentThread().getStackTrace()) { if (foundReadObject) { traceWriter.println("\t at " + element.getClassName() + "." + element.getMethodName()); } else if (element.getClassName().equals(ObjectInputStream.class.getName()) && element.getMethodName().equals("readObject")) { foundReadObject = true; } } } } }
From source file:Main.java
public static String getLogInfo(StackTraceElement stackTraceElement) { StringBuilder logInfoStringBuilder = new StringBuilder(); String threadName = Thread.currentThread().getName(); long threadID = Thread.currentThread().getId(); String fileName = stackTraceElement.getFileName(); String className = stackTraceElement.getClassName(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); logInfoStringBuilder.append("[ "); logInfoStringBuilder.append("threadID=" + threadID).append(SEPARATOR); logInfoStringBuilder.append("threadName=" + threadName).append(SEPARATOR); logInfoStringBuilder.append("fileName=" + fileName).append(SEPARATOR); logInfoStringBuilder.append("className=" + className).append(SEPARATOR); logInfoStringBuilder.append("methodName=" + methodName).append(SEPARATOR); logInfoStringBuilder.append("lineNumber=" + lineNumber); logInfoStringBuilder.append(" ] "); return logInfoStringBuilder.toString(); }
From source file:alluxio.util.io.PathUtils.java
/** * Creates a unique path based off the caller. * * @return unique path based off the caller */// w ww .ja va 2 s. c o m public static String uniqPath() { StackTraceElement caller = new Throwable().getStackTrace()[1]; long time = System.nanoTime(); return "/" + caller.getClassName() + "/" + caller.getMethodName() + "/" + time; }
From source file:org.wso2.carbon.registry.core.pagination.PaginationUtils.java
/** * Check the resource get method is paginated or not. * @param annotation method annotation name * @return true if the method id paginated. *///from ww w .jav a 2 s .c om public static boolean isPaginationAnnotationFound(String annotation) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stackTrace) { try { Method[] methods = Class.forName(element.getClassName()).getMethods(); for (Method method : methods) { if (method.getName().equals(element.getMethodName()) && method.isAnnotationPresent(Paginate.class) && method.getAnnotation(Paginate.class).value().equals(annotation)) { return true; } } } catch (ClassNotFoundException ignore) { } } return false; }
From source file:grails.util.GrailsUtil.java
public static void printSanitizedStackTrace(Throwable t, PrintWriter p, StackTraceFilterer stackTraceFilterer) { t = stackTraceFilterer.filter(t);/*from ww w. j a va 2 s. co m*/ StackTraceElement[] trace = t.getStackTrace(); for (StackTraceElement stackTraceElement : trace) { p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + ")"); } }
From source file:Main.java
private static void formatState(final StringBuilder sb, final ThreadInfo info) { final Thread.State state = info.getThreadState(); sb.append(state);//from w ww . ja va 2 s. c o m switch (state) { case BLOCKED: { sb.append(" (on object monitor owned by \""); sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()).append(")"); break; } case WAITING: { final StackTraceElement element = getStackForThread(info.getThreadId())[0]; final String className = element.getClassName(); final String method = element.getMethodName(); if (className.equals("java.lang.Object") && method.equals("wait")) { sb.append(" (on object monitor"); if (info.getLockOwnerName() != null) { sb.append(" owned by \""); sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()); } sb.append(")"); } else if (className.equals("java.lang.Thread") && method.equals("join")) { sb.append(" (on completion of thread ").append(info.getLockOwnerId()).append(")"); } else { sb.append(" (parking for lock"); if (info.getLockOwnerName() != null) { sb.append(" owned by \""); sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()); } sb.append(")"); } break; } case TIMED_WAITING: { final StackTraceElement element = info.getStackTrace()[0]; final String className = element.getClassName(); final String method = element.getMethodName(); if (className.equals("java.lang.Object") && method.equals("wait")) { sb.append(" (on object monitor"); if (info.getLockOwnerName() != null) { sb.append(" owned by \""); sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()); } sb.append(")"); } else if (className.equals("java.lang.Thread") && method.equals("sleep")) { sb.append(" (sleeping)"); } else if (className.equals("java.lang.Thread") && method.equals("join")) { sb.append(" (on completion of thread ").append(info.getLockOwnerId()).append(")"); } else { sb.append(" (parking for lock"); if (info.getLockOwnerName() != null) { sb.append(" owned by \""); sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()); } sb.append(")"); } break; } default: break; } }