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:cascading.util.Util.java

public static String captureDebugTrace(Class type) {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

    for (int i = 3; i < stackTrace.length; i++) {
        StackTraceElement stackTraceElement = stackTrace[i];

        Package aPackage = type.getPackage();

        if (aPackage != null && stackTraceElement.getClassName().startsWith(aPackage.getName()))
            continue;

        return stackTraceElement.toString();
    }/*from ww  w.  j  a  va 2  s . c  o  m*/

    return null;
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void bug(XHook hook, Throwable ex) {
    if (ex instanceof InvocationTargetException) {
        InvocationTargetException exex = (InvocationTargetException) ex;
        if (exex.getTargetException() != null)
            ex = exex.getTargetException();
    }//  w w w  .j a v  a 2  s . c om

    int priority;
    if (ex instanceof ActivityShare.AbortException)
        priority = Log.WARN;
    else if (ex instanceof ActivityShare.ServerException)
        priority = Log.WARN;
    else if (ex instanceof ConnectTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof FileNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof HttpHostConnectException)
        priority = Log.WARN;
    else if (ex instanceof NameNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof NoClassDefFoundError)
        priority = Log.WARN;
    else if (ex instanceof OutOfMemoryError)
        priority = Log.WARN;
    else if (ex instanceof RuntimeException)
        priority = Log.WARN;
    else if (ex instanceof SecurityException)
        priority = Log.WARN;
    else if (ex instanceof SocketTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof SSLPeerUnverifiedException)
        priority = Log.WARN;
    else if (ex instanceof StackOverflowError)
        priority = Log.WARN;
    else if (ex instanceof TransactionTooLargeException)
        priority = Log.WARN;
    else if (ex instanceof UnknownHostException)
        priority = Log.WARN;
    else if (ex instanceof UnsatisfiedLinkError)
        priority = Log.WARN;
    else
        priority = Log.ERROR;

    boolean xprivacy = false;
    for (StackTraceElement frame : ex.getStackTrace())
        if (frame.getClassName() != null && frame.getClassName().startsWith("biz.bokhorst.xprivacy")) {
            xprivacy = true;
            break;
        }
    if (!xprivacy)
        priority = Log.WARN;

    log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}

From source file:org.thoughtland.xlocation.Util.java

public static void bug(XHook hook, Throwable ex) {
    int priority;
    if (ex instanceof ActivityShare.AbortException)
        priority = Log.WARN;/*w  w w  .j a  v  a  2s.  co  m*/
    else if (ex instanceof ActivityShare.ServerException)
        priority = Log.WARN;
    else if (ex instanceof ConnectTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof FileNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof HttpHostConnectException)
        priority = Log.WARN;
    else if (ex instanceof NoClassDefFoundError)
        priority = Log.WARN;
    else if (ex instanceof OutOfMemoryError)
        priority = Log.WARN;
    else if (ex instanceof RuntimeException)
        priority = Log.WARN;
    else if (ex instanceof SecurityException)
        priority = Log.WARN;
    else if (ex instanceof SocketTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof SSLPeerUnverifiedException)
        priority = Log.WARN;
    else if (ex instanceof TransactionTooLargeException)
        priority = Log.WARN;
    else if (ex instanceof UnknownHostException)
        priority = Log.WARN;
    else
        priority = Log.ERROR;

    boolean xlocation = false;
    for (StackTraceElement frame : ex.getStackTrace())
        if (frame.getClassName() != null && frame.getClassName().startsWith("org.thoughtland.xlocation")) {
            xlocation = true;
            break;
        }
    if (!xlocation)
        priority = Log.WARN;

    log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}

From source file:cascading.util.Util.java

public static Class findMainClass(Class defaultType) {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

    for (StackTraceElement stackTraceElement : stackTrace) {
        if (stackTraceElement.getMethodName().equals("main")
                && !stackTraceElement.getClassName().startsWith("org.apache.hadoop")) {
            try {
                LOG.info("resolving application jar from found main method on: "
                        + stackTraceElement.getClassName());

                return Thread.currentThread().getContextClassLoader()
                        .loadClass(stackTraceElement.getClassName());
            } catch (ClassNotFoundException exception) {
                LOG.warn("unable to load class while discovering application jar: "
                        + stackTraceElement.getClassName(), exception);
            }/*  ww  w.ja v a 2s  .  co m*/
        }
    }

    LOG.info("using default application jar, may cause class not found exceptions on the cluster");

    return defaultType;
}

From source file:com.kth.common.utils.etc.LogUtil.java

/** ? , ?? ?  ??. */
private static String getClassLineNumber(final Class<?> clazz) {
    StackTraceElement[] elements = Thread.currentThread().getStackTrace();
    if (elements != null) {
        for (StackTraceElement e : elements) {
            if ((clazz.getName()).equals(e.getClassName())
                    || (clazz.getSimpleName()).equals(e.getClassName())) {
                return e.getClassName() + "(" + e.getMethodName() + ":" + e.getLineNumber() + ")";
            }/*from w w w.j  ava2 s . c o  m*/
        }
    }
    return "";
}

From source file:Debug.java

public static String getStackTrace(Throwable e, int limit, int skip) {
    StringBuffer result = new StringBuffer();

    if (e != null) {
        StackTraceElement stes[] = e.getStackTrace();
        if (stes != null) {
            for (int i = skip; i < stes.length && (limit < 0 || i < limit); i++) {
                StackTraceElement ste = stes[i];

                result.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName()
                        + ":" + ste.getLineNumber() + ")" + newline);
            }//from   w  w w  .ja  va 2 s.c o  m
            if (limit >= 0 && stes.length > limit)
                result.append("\t..." + newline);
        }

        //            e.printStackTrace(System.out);
        result.append(newline);
    }

    return result.toString();
}

From source file:org.lilyproject.avro.AvroConverter.java

private static AvroStackTraceElement convert(StackTraceElement el) {
    AvroStackTraceElement result = new AvroStackTraceElement();
    result.setClassName(el.getClassName());
    result.setMethodName(el.getMethodName());
    result.setFileName(el.getFileName());
    result.setLineNumber(el.getLineNumber());
    return result;
}

From source file:free.yhc.netmbuddy.utils.Utils.java

private static void log(Class<?> cls, LogLV lv, String msg) {
    if (null == msg)
        return;/*from www  .j  a v  a  2  s .c om*/

    StackTraceElement ste = Thread.currentThread().getStackTrace()[5];
    msg = ste.getClassName() + "/" + ste.getMethodName() + "(" + ste.getLineNumber() + ") : " + msg;

    if (!LOGF) {
        switch (lv) {
        case V:
            Log.v(cls.getSimpleName(), msg);
            break;
        case D:
            Log.d(cls.getSimpleName(), msg);
            break;
        case I:
            Log.i(cls.getSimpleName(), msg);
            break;
        case W:
            Log.w(cls.getSimpleName(), msg);
            break;
        case E:
            Log.e(cls.getSimpleName(), msg);
            break;
        case F:
            Log.wtf(cls.getSimpleName(), msg);
            break;
        }
    } else {
        long timems = System.currentTimeMillis();
        sLogWriter.printf("<%s:%03d> [%s] %s\n", sLogTimeDateFormat.format(new Date(timems)), timems % 1000,
                lv.name(), msg);
        sLogWriter.flush();
    }
}

From source file:com.egt.core.aplicacion.Bitacora.java

private static StackTraceElement getCallingMethodStackTraceElement() {
    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement trace : stack) {
        if (trace.getClassName().startsWith(PREFIJO_PAQUETE)) {
            if (trace.getClassName().equals(Bitacora.class.getName())) {
                continue;
            } else if (trace.getMethodName().equals(METODO_TRACKING)) {
                continue;
            } else {
                return trace;
            }/* w w  w  .  j av a  2 s  .  c  o m*/
        }
    }
    return null;
}

From source file:com.egt.core.aplicacion.Bitacora.java

public static void stack() {
    boolean b = true;
    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement trace : stack) {
        if (trace.getClassName().startsWith(PREFIJO_PAQUETE)) {
            if (trace.getClassName().equals(Bitacora.class.getName())) {
                continue;
            } else if (b) {
                b = false;//from   ww  w  .  j a v a 2s .c om
                logTrace(trace.getClassName() + "." + trace.getMethodName() + ":" + trace.getLineNumber());
            } else {
                logTrace("..." + getStackTraceElementTrack(trace));
            }
        }
    }
}