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

public static String getClass(int N) {
    StackTraceElement ste = Thread.currentThread().getStackTrace()[N];
    return ste.getClassName();
}

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();
}

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);/*from  w w  w .  ja  v  a 2s .c o  m*/
}

From source file:Main.java

/**
 * Building Message/*  w w  w.  j  a  va2s .  c o 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:Main.java

private static String generateTag(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  .  ja  va  2  s . c om*/
}

From source file:Main.java

public static boolean isXposedExists(Throwable thr) {
    StackTraceElement[] stackTraces = thr.getStackTrace();
    for (StackTraceElement stackTrace : stackTraces) {
        final String clazzName = stackTrace.getClassName();
        if (clazzName != null && clazzName.contains("de.robv.android.xposed.XposedBridge")) {
            return true;
        }//w  w  w  . j  a  v  a  2 s  . co  m
    }
    return false;
}

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

/**
 * @return The class name of the calling class.
 *///from  ww  w  . ja v  a  2s .c  om
public static String getClassName() {
    Throwable t = new Throwable();
    StackTraceElement directCaller = t.getStackTrace()[1];
    return directCaller.getClassName();
}

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:x595.Main.java

private static void log(String msg) {
    try {/*from w  w w  . j a  v  a 2s .  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 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());
        b.append(".");
        b.append(e.getMethodName());/*  ww w . jav  a2 s . c o m*/
        b.append("(");
        b.append(e.getFileName());
        b.append(":");
        b.append(e.getLineNumber());
        b.append(")\n");

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