Example usage for java.lang StackTraceElement getClassName

List of usage examples for java.lang StackTraceElement getClassName

Introduction

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

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class containing the execution point represented by this stack trace element.

Usage

From source file:Main.java

private static String generateVerboseTag(StackTraceElement caller) {
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*ww  w.  j a v  a 2s .  c  om*/
}

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

private static String generateTag(StackTraceElement caller) {
    String tag = "%s.%s(Line:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*  w ww. jav  a2 s.c o m*/
}

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");
        }/* ww w  .  j a v a  2  s  .com*/
        sb.append("\n\n");
    }
}

From source file:com.jaeksoft.searchlib.util.ExceptionUtils.java

public final static String getLocation(StackTraceElement[] stackTrace) {
    for (StackTraceElement element : stackTrace)
        if (element.getClassName().startsWith("com.jaeksoft"))
            return element.toString();
    return null;/* w w  w  .ja v  a2s  .c o m*/
}

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);//from   w w w  . ja  v  a 2  s. c  o m
    }
    Log.d(tag, msg + " --- stack trace ends.");
}

From source file:Main.java

private static void print(StackTraceElement element, Object message, Throwable error) {
    String className = element.getClassName();
    className = className.substring(className.lastIndexOf(".") + 1);
    String tag = className + '.' + element.getMethodName() + '(' + element.getFileName() + ':'
            + element.getLineNumber() + ')';
    String text = toString(message);

    if (error != null) {
        Log.e("[KakaCache]", tag + "\n\t" + text, error);
    } else {/*w w w . ja v a  2s.  c o  m*/
        Log.e("[KakaCache]", tag + "\n\t" + text);
    }
}

From source file:Main.java

public static String getCallLocation(String fqn) {
    if (!java13) {
        try {/*from   w  w  w. jav  a  2s.c o m*/
            StackTraceElement[] ste = new Throwable().getStackTrace();
            for (int i = 0; i < ste.length - 1; i++) {
                if (fqn.equals(ste[i].getClassName())) {
                    StackTraceElement callLocation = ste[i + 1];
                    String nextClassName = callLocation.getClassName();
                    if (nextClassName.equals(fqn)) {
                        continue;
                    }
                    return callLocation.toString();
                }
            }
        } catch (Throwable e) {
            java13 = true;
        }
    }
    return null;
}

From source file:Main.java

public static void openFeedback(Activity activity) {
    try {/*  w ww . j a v  a 2  s .  c  o  m*/
        throw new Exception();
    } catch (Exception e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication().getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}

From source file:org.eurekastreams.commons.logging.LogFactory.java

/**
 * Make a log for the calling class.//from  w  w w . j a v a 2 s. co m
 *
 * @return a log for the calling class
 */
public static Log make() {
    Throwable t = new Throwable();
    StackTraceElement directCaller = t.getStackTrace()[1];
    return org.apache.commons.logging.LogFactory.getLog(directCaller.getClassName());
}