Example usage for java.lang StackTraceElement getMethodName

List of usage examples for java.lang StackTraceElement getMethodName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getMethodName.

Prototype

public String getMethodName() 

Source Link

Document

Returns the name of the method containing the execution point represented by this stack trace element.

Usage

From source file:Main.java

public static void printStackTrace(final StackTraceElement[] stack, StringBuffer b) {
    for (int i = 0; i < stack.length; ++i) {
        StackTraceElement e = stack[i];
        b.append("\t at ");
        b.append(e.getClassName());//from   w  ww  .j  a v  a  2 s. com
        b.append(".");
        b.append(e.getMethodName());
        b.append("(");
        b.append(e.getFileName());
        b.append(":");
        b.append(e.getLineNumber());
        b.append(")\n");

    }
    //b.append("\n");
}

From source file:Main.java

public static void trace(Object object) {
    if (logTrace) {
        StackTraceElement[] traces = Thread.currentThread().getStackTrace();
        StackTraceElement trace = traces[3];
        android.util.Log.d(TAG_TRACE,//  w  w  w  .j a v a 2s .  c  o  m
                addThreadInfo(object.getClass().getSimpleName() + " : " + trace.getMethodName()));
    }
}

From source file:me.j360.dubbo.modules.util.concurrent.ThreadUtil.java

/**
 * StackTrace"??.??()"//from   ww  w .  j av a  2  s. co  m
 */
public static String getCallerMethod() {
    StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
    if (stacktrace.length >= 4) {
        StackTraceElement element = stacktrace[3];
        return element.getClassName() + '.' + element.getMethodName() + "()";
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:me.j360.dubbo.modules.util.concurrent.ThreadUtil.java

/**
 * StackTrace?"??.??()"/*w  w w  . ja  va2 s. c  o m*/
 */
public static String getCurrentMethod() {
    StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
    if (stacktrace.length >= 3) {
        StackTraceElement element = stacktrace[2];
        return element.getClassName() + '.' + element.getMethodName() + "()";
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:com.cloud.utils.ProcessUtil.java

public static String dumpStack() {
    StringBuilder sb = new StringBuilder();
    StackTraceElement[] elems = Thread.currentThread().getStackTrace();
    if (elems != null && elems.length > 0) {
        for (StackTraceElement elem : elems) {
            sb.append("\tat ").append(elem.getMethodName()).append("(").append(elem.getFileName()).append(":")
                    .append(elem.getLineNumber()).append(")\n");
        }//from w  w  w . jav a  2 s.c om
    }
    return sb.toString();
}

From source file:Main.java

public static String getCallerNoPackageClassNameMethod() {
    final StackTraceElement el = Thread.currentThread().getStackTrace()[2];
    final String noPackageClassName = el.getClassName().replaceAll(".*\\.", "");
    final String methodName = el.getMethodName();
    final String retval = noPackageClassName + "." + methodName;
    return retval;

}

From source file:Main.java

public static String TAG() {
    StackTraceElement stacktrace = Thread.currentThread().getStackTrace()[3];
    return "NITRO:" + stacktrace.getClassName().substring("com.qweex.callisto".length() + 1) + ":"
            + stacktrace.getMethodName() + "::" + stacktrace.getLineNumber();
}

From source file:com.ikon.util.StackTraceUtils.java

/**
 * Return the method who make the call.//from w  ww . ja  v a  2 s .co m
 */
public static void logTrace(Logger log) {
    // The constructor for Throwable has a native function that fills the stack trace.
    StackTraceElement[] trace = (new Throwable()).getStackTrace();

    // Once you have the trace you can pick out information you need.
    if (trace.length >= 2) {
        for (int i = 2; i < trace.length; i++) {
            if (trace[i].getClassName().startsWith("com.ikon")) {
                StackTraceElement sse = trace[i];
                log.warn("{} -> {} ({}:{})", new Object[] { sse.getClassName(), sse.getMethodName(),
                        sse.getFileName(), sse.getLineNumber() });
            }
        }
    }
}

From source file:com.openkm.util.StackTraceUtils.java

/**
 * Return the method who make the call./*from w  w  w  . j  a  va 2s .c  o  m*/
 */
public static void logTrace(Logger log) {
    // The constructor for Throwable has a native function that fills the stack trace.
    StackTraceElement[] trace = (new Throwable()).getStackTrace();

    // Once you have the trace you can pick out information you need.
    if (trace.length >= 2) {
        for (int i = 2; i < trace.length; i++) {
            if (trace[i].getClassName().startsWith("com.openkm")) {
                StackTraceElement sse = trace[i];
                log.warn("{} -> {} ({}:{})", new Object[] { sse.getClassName(), sse.getMethodName(),
                        sse.getFileName(), sse.getLineNumber() });
            }
        }
    }
}

From source file:Main.java

public static final void log(String message) {
    StackTraceElement ste = Thread.currentThread().getStackTrace()[3];
    String className = ste.getClassName();
    className = className.substring(className.lastIndexOf(".") + 1);
    String methodName = ste.getMethodName();
    int lineNum = ste.getLineNumber();
    String logText = String.format("%s(%s):%s", methodName, lineNum, message);
    Log.d(className, logText);/*  ww w .  ja  v  a 2  s  .  co m*/
}