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:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java

public static String traceIdentityHash(ErrorReport report) {
    final Hasher hasher = Hashing.murmur3_128().newHasher();
    visit(report, new ModelSwitch<Hasher>() {

        @Override/*from  w ww.  ja  va  2s  . c  om*/
        public Hasher caseStackTraceElement(StackTraceElement element) {
            hasher.putString(element.getClassName(), UTF_8);
            hasher.putString(element.getMethodName(), UTF_8);
            hasher.putInt(element.getLineNumber());
            return null;
        }
    });
    String hash = hasher.hash().toString();
    return hash;
}

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

/**
 * Stack Trace  ?./*from  w w w  .  ja  va  2 s .  c  o m*/
 * 
 * @param clazz  ??  Class.
 * @param level  .
 * @param msg .
 */
public static void stackTrace(final Class<?> clazz, final int level, final String msg) {
    if (Log.isLoggable(TAG, level)) {
        Thread th = Thread.currentThread();
        StackTraceElement[] stack = th.getStackTrace();

        StringBuilder sb = new StringBuilder();
        if (msg != null && !"".equals(msg)) {
            sb.append(msg).append("\n");
        }
        for (StackTraceElement element : stack) {
            if (!"getStackTrace".equals(element.getMethodName())
                    && !"stackTrace".equals(element.getMethodName())) {
                sb.append("\tat ").append(element.toString()).append("\n");
            }
        }
        Log.println(level, TAG, LogUtil.getClassLineNumber(clazz) + " - " + sb.toString());
    }
}

From source file:org.apache.jorphan.util.JOrphanUtils.java

/**
 * Display currently running threads on system.out
 * This may be expensive to run./*from ww w  .  j  a va  2s. c  om*/
 * Mainly designed for use at the end of a non-GUI test to check for threads that might prevent the JVM from exiting.
 *
 * @param includeDaemons whether to include daemon threads or not.
 */
public static void displayThreads(boolean includeDaemons) {
    Map<Thread, StackTraceElement[]> m = Thread.getAllStackTraces();
    String lineSeparator = System.getProperty("line.separator");
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<Thread, StackTraceElement[]> e : m.entrySet()) {
        boolean daemon = e.getKey().isDaemon();
        if (includeDaemons || !daemon) {
            builder.setLength(0);
            StackTraceElement[] ste = e.getValue();
            for (StackTraceElement stackTraceElement : ste) {
                int lineNumber = stackTraceElement.getLineNumber();
                builder.append(stackTraceElement.getClassName() + "#" + stackTraceElement.getMethodName()
                        + (lineNumber >= 0 ? " at line:" + stackTraceElement.getLineNumber() : "")
                        + lineSeparator);
            }
            System.out.println(e.getKey().toString() + ((daemon ? " (daemon)" : "")) + ", stackTrace:"
                    + builder.toString());
        }
    }
}

From source file:org.eclipse.wb.internal.core.utils.exception.DesignerExceptionUtils.java

/**
 * @return <code>true</code> if given {@link Throwable} has given sequence on class/method names.
 *//*  w w  w  .  ja v  a 2  s .c  om*/
public static boolean hasTraceElementsSequence(Throwable e, String[][] expected) {
    StackTraceElement[] elements = e.getStackTrace();
    traceElements: for (int i = 0; i < elements.length; i++) {
        for (int j = 0; j < expected.length; j++) {
            if (i + j < elements.length) {
                StackTraceElement element = elements[i + j];
                String expectedClass = expected[j][0];
                String expectedMethod = expected[j][1];
                if (element.getClassName().equals(expectedClass)
                        && element.getMethodName().equals(expectedMethod)) {
                    continue;
                }
            }
            continue traceElements;
        }
        return true;
    }
    return false;
}

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 . jav  a2  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.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Write out the code for passed Class./*from   w ww. j  a  va  2  s . c om*/
 * @param out
 * @param c
 * @throws IOException
 */
static void writeClassCode(final DataOutput out, final Class<?> c) throws IOException {
    Integer code = getClassCode(c);

    if (code == null) {
        LOG.error("Unsupported type " + c);
        StackTraceElement[] els = new Exception().getStackTrace();
        for (StackTraceElement elem : els) {
            LOG.error(elem.getMethodName());
        }
        throw new UnsupportedOperationException("No code for unexpected " + c);
    }
    WritableUtils.writeVInt(out, code);
}

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;/* w ww . j a v  a2 s  .com*/

    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 String getStackTraceElementTrack(StackTraceElement trace) {
    return trace == null ? ""
            : " @ " + getSimpleClassName(trace.getClassName()) + "." + trace.getMethodName() + ":"
                    + trace.getLineNumber();
}

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

/**
 * This will produce html highlighted stacktrace
 *
 * @param throwable/*from   w  ww  .  j  a  v a2 s. c  o m*/
 * @return
 */
public static String parseStackTraceHtml(Throwable throwable) {
    StringBuilder exception = new StringBuilder();

    if (throwable != null) {
        String message = throwable.getMessage();
        if (StringUtils.isNotBlank(message)) {
            exception.append("<b>Message:</b> <span style='color: red;'><b>")
                    .append(message.replace("\n", "<br>")).append("</b><br>");
        }
        for (StackTraceElement stackTraceElement : throwable.getStackTrace()) {
            String style = "color: grey; font-size: 10px;";
            if (stackTraceElement.getClassName().contains("edu.usu.sdl")) {
                style = "color: black; font-size: 12px; font-wieght: bold;";
            }
            exception.append("<span style='").append(style).append("'>")
                    .append(stackTraceElement.getClassName()).append(" (")
                    .append(stackTraceElement.getMethodName()).append(") : ")
                    .append(stackTraceElement.getLineNumber()).append(" ").append("</span><br>");
        }
        if (throwable.getSuppressed().length > 0) {
            exception.append("Suppress Exceptions: ");
            for (Throwable suppressed : throwable.getSuppressed()) {
                exception.append(parseStackTraceHtml(suppressed)).append("<br>");
            }
        }

        if (throwable.getCause() != null) {

        }
    }

    return exception.toString();
}