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:io.stallion.services.Log.java

public static void info(String message, Object... args) {
    if (getLogLevel().intValue() > Level.INFO.intValue()) {
        return;//from   ww  w.ja v a 2s .co m
    }
    // Info statements don't include the class and line number, since that kills performance
    //System.out.println(message);
    if (alwaysIncludeLineNumber) {
        Throwable t = new Throwable();
        StackTraceElement stackTraceElement = t.getStackTrace()[1];
        String clz = stackTraceElement.getClassName().replace("io.stallion.", "");
        String method = stackTraceElement.getMethodName() + ":" + t.getStackTrace()[1].getLineNumber();
        logger.logp(Level.INFO, clz, method, message, args);
    } else {
        logger.logp(Level.INFO, "", "", message, args);
    }

}

From source file:org.kantega.notsoserial.NotSoSerialClassFileTransformer.java

public static void registerDeserialization(String className) {
    Set<String> deserializingClasses = NotSoSerialClassFileTransformer.deserializingClasses;
    if (!deserializingClasses.contains(className)) {
        deserializingClasses.add(className);
        String prettyName = className.replace('/', '.');
        dryRunWriter.println(prettyName);
        dryRunWriter.flush();//from   ww w .j  ava  2 s .c  o m
        if (traceWriter != null) {
            traceWriter
                    .println("Deserialization of class " + prettyName + " (on " + new Date().toString() + ")");
            boolean foundReadObject = false;
            for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
                if (foundReadObject) {
                    traceWriter.println("\t at " + element.getClassName() + "." + element.getMethodName());
                } else if (element.getClassName().equals(ObjectInputStream.class.getName())
                        && element.getMethodName().equals("readObject")) {
                    foundReadObject = true;
                }
            }
        }
    }
}

From source file:org.kepler.sms.SemanticType.java

private static boolean isGoodTrace(StackTraceElement[] stackTrace) {
    for (StackTraceElement ste : stackTrace) {
        if ("org.kepler.sms.SemanticType".equals(ste.getClassName()) && ste.getLineNumber() == 75) {
            return false;
        }/*from w  w w .jav  a2 s.c om*/
    }
    return true;
}

From source file:Main.java

private static void formatState(final StringBuilder sb, final ThreadInfo info) {
    final Thread.State state = info.getThreadState();
    sb.append(state);//from   w ww .  j  a  v  a 2s  .co  m
    switch (state) {
    case BLOCKED: {
        sb.append(" (on object monitor owned by \"");
        sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()).append(")");
        break;
    }
    case WAITING: {
        final StackTraceElement element = getStackForThread(info.getThreadId())[0];
        final String className = element.getClassName();
        final String method = element.getMethodName();
        if (className.equals("java.lang.Object") && method.equals("wait")) {
            sb.append(" (on object monitor");
            if (info.getLockOwnerName() != null) {
                sb.append(" owned by \"");
                sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId());
            }
            sb.append(")");
        } else if (className.equals("java.lang.Thread") && method.equals("join")) {
            sb.append(" (on completion of thread ").append(info.getLockOwnerId()).append(")");
        } else {
            sb.append(" (parking for lock");
            if (info.getLockOwnerName() != null) {
                sb.append(" owned by \"");
                sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId());
            }
            sb.append(")");
        }
        break;
    }
    case TIMED_WAITING: {
        final StackTraceElement element = info.getStackTrace()[0];
        final String className = element.getClassName();
        final String method = element.getMethodName();
        if (className.equals("java.lang.Object") && method.equals("wait")) {
            sb.append(" (on object monitor");
            if (info.getLockOwnerName() != null) {
                sb.append(" owned by \"");
                sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId());
            }
            sb.append(")");
        } else if (className.equals("java.lang.Thread") && method.equals("sleep")) {
            sb.append(" (sleeping)");
        } else if (className.equals("java.lang.Thread") && method.equals("join")) {
            sb.append(" (on completion of thread ").append(info.getLockOwnerId()).append(")");
        } else {
            sb.append(" (parking for lock");
            if (info.getLockOwnerName() != null) {
                sb.append(" owned by \"");
                sb.append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId());
            }
            sb.append(")");
        }
        break;
    }
    default:
        break;
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java

static String getFilteredStackTrace(String filter) {
    Exception e = new Exception();
    StackTraceElement[] stackTrace = e.getStackTrace();
    StringBuilder sb = new StringBuilder();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().contains(filter)) {
            sb.append(element.toString()).append("\n");
        }//from  w  w w . jav a2s.  c o  m
    }
    return sb.toString();
}

From source file:com.gtwm.pb.servlets.ServletUtilMethods.java

/**
 * Return a string for logging purposes, of an exception's 'cause stack',
 * i.e. the original exception(s) thrown and stack trace, i.e. the methods
 * that the exception was thrown through.
 * /*from   w w  w.j  av  a  2 s. c om*/
 * Called by logException
 */
private static String getExceptionCauses(Exception ex) {
    String errorMessage = ex.toString() + "\r\n";
    if (ex.getCause() != null) {
        // Recursively find causes of exception
        errorMessage += " - Error was due to...";
        Exception exceptionCause = ex;
        String causeIndent = " - ";
        errorMessage += causeIndent + ex.toString() + "\r\n";
        while (exceptionCause.getCause() != null) {
            if (exceptionCause.getCause() instanceof Exception) {
                exceptionCause = (Exception) exceptionCause.getCause();
                causeIndent += " - ";
                errorMessage += causeIndent + getExceptionCauses(exceptionCause);
            }
        }
    }
    // Include out relevant parts of the stack trace
    StackTraceElement[] stackTrace = ex.getStackTrace();
    if (stackTrace.length > 0) {
        errorMessage += " - Stack trace:\r\n";
        int nonGtwmClassesLogged = 0;
        for (StackTraceElement stackTraceElement : stackTrace) {
            if (!stackTraceElement.getClassName().startsWith("com.gtwm.")) {
                nonGtwmClassesLogged++;
            }
            // Only trace our own classes + a few more, stop shortly after
            // we get to java language or 3rd party classes
            if (nonGtwmClassesLogged < 15) {
                errorMessage += "   " + stackTraceElement.toString() + "\r\n";
            }
        }
    }
    return errorMessage;
}

From source file:alluxio.util.io.PathUtils.java

/**
 * Creates a unique path based off the caller.
 *
 * @return unique path based off the caller
 *//*from w w  w  .j a  v a 2s .c  om*/
public static String uniqPath() {
    StackTraceElement caller = new Throwable().getStackTrace()[1];
    long time = System.nanoTime();
    return "/" + caller.getClassName() + "/" + caller.getMethodName() + "/" + time;
}

From source file:com.snicesoft.basekit.LogKit.java

private static String generateTag(StackTraceElement caller) {
    //        String tag = "%s.%s(L:%d)";
    String tag = "%s.%s(" + caller.getFileName() + ":%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;/*from   w  w w .j  a va2s.  c  o m*/
}

From source file:grails.util.GrailsUtil.java

public static void printSanitizedStackTrace(Throwable t, PrintWriter p, StackTraceFilterer stackTraceFilterer) {
    t = stackTraceFilterer.filter(t);/*from w  w w .j  a va2  s . c o m*/

    StackTraceElement[] trace = t.getStackTrace();
    for (StackTraceElement stackTraceElement : trace) {
        p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":"
                + stackTraceElement.getLineNumber() + ")");
    }
}

From source file:com.tasktop.c2c.server.scm.web.GitHandler.java

private static boolean computeContainerSupportsChunkedIO() {
    synchronized (GitHandler.class) {
        if (chunkedIOContainerSupported == null) {
            boolean supported = true;
            for (StackTraceElement stackTrace : Thread.currentThread().getStackTrace()) {
                if (stackTrace.getClassName().contains("winstone")) {
                    supported = false;/*from  w w  w  .  j  a  v  a  2  s .co  m*/
                    break;
                }
            }
            chunkedIOContainerSupported = supported;
        }
    }
    return chunkedIOContainerSupported;
}