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:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java

private void removeJenaClassesFromStackTrace(List<StackTraceElement> list) {
    ListIterator<StackTraceElement> iter = list.listIterator();
    while (iter.hasNext()) {
        StackTraceElement ste = iter.next();
        if (ste.getClassName().startsWith("com.hp.hpl.jena.")) {
            iter.remove();/*from  w ww.  j  a  va  2 s  . com*/
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java

private void trimStackTraceAtBeginning(List<StackTraceElement> list) {
    ListIterator<StackTraceElement> iter = list.listIterator();
    while (iter.hasNext()) {
        StackTraceElement ste = iter.next();
        if (ste.getClassName().equals(lowestClassInStackTrace.getName())) {
            break;
        } else {/*from w w  w.j  a  va 2 s .  c  om*/
            iter.remove();
        }
    }
}

From source file:gumga.framework.application.GumgaLoggerService.java

public String createLogLine(String msg, int level) {
    StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level];
    String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " "
            + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n";
    return line;//from www. ja  v  a  2  s  .  c o m

}

From source file:org.gradle.test.fixtures.file.TestNameTestDirectoryProvider.java

private String determinePrefix() {
    StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().endsWith("Test") || element.getClassName().endsWith("Spec")) {
            return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test-"
                    + testCounter.getAndIncrement();
        }//  w  ww. j av a2  s . com
    }
    return "unknown-test-class-" + testCounter.getAndIncrement();
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java

private String assembleCallStackString() {
    StringBuilder stack = new StringBuilder();
    for (StackTraceElement ste : stackTrace) {
        stack.append(ste.getClassName()).append(" ").append(ste.getMethodName()).append(" ");
    }//  w  ww .  java 2  s .c om
    return stack.deleteCharAt(stack.length() - 1).toString();
}

From source file:es.bsc.servicess.ide.Logger.java

private String printInvocationInfo(StackTraceElement invoker) {
    return "[" + invoker.getClassName() + "." + invoker.getMethodName() + "(" + invoker.getFileName() + ":"
            + invoker.getLineNumber() + ")]";
}

From source file:io.gumga.application.GumgaLoggerService.java

/**
 *
 * @param msg mensagem do log/*w w w.ja  va2 s.c  o m*/
 * @param level index da execption do StrackTrace
 * @return dados do log
 */
public String createLogLine(String msg, int level) {
    StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level];
    String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " "
            + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n";
    return line;

}

From source file:cn.bran.play.JapidTemplateBase.java

@Override
protected void handleException(RuntimeException e) {
    if (Play.mode == Mode.PROD)
        throw e;/*w ww  .  j a  va  2 s .  c om*/

    // find the latest japidviews exception
    StackTraceElement[] stackTrace = e.getStackTrace();
    for (StackTraceElement ele : stackTrace) {
        String className = ele.getClassName();
        if (className.startsWith("japidviews")) {
            int lineNumber = ele.getLineNumber();
            // TODO: should really remove the Play reference.  Shall we jump to the file system for the source?
            ApplicationClass applicationClass = Play.classes.getApplicationClass(className);
            if (applicationClass != null) {
                // let's get the line of problem
                String jsrc = applicationClass.javaSource;
                String[] splitSrc = jsrc.split("\n");
                String line = splitSrc[lineNumber - 1];
                // can we have a line marker?
                int lineMarker = line.lastIndexOf("// line ");
                if (lineMarker > 0) {
                    int oriLineNumber = Integer.parseInt(line.substring(lineMarker + 8).trim());
                    StackTraceElement[] newStack = new StackTraceElement[stackTrace.length + 1];
                    newStack[0] = new StackTraceElement(sourceTemplate, "", sourceTemplate, oriLineNumber);
                    System.arraycopy(stackTrace, 0, newStack, 1, stackTrace.length);
                    e.setStackTrace(newStack);

                    File file = new File("app/" + sourceTemplate);
                    //         
                    JapidPlayTemplate jpt = new JapidPlayTemplate();
                    jpt.name = sourceTemplate;
                    try {
                        jpt.source = FileUtils.readFileToString(file);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                    throw new TemplateExecutionException(jpt, oriLineNumber, e.getMessage(), e);
                }
            }
        }
    }
    throw e;
}

From source file:net.logstash.logback.encoder.LogstashEncoderV1.java

@Override
public void doEncode(ILoggingEvent event) throws IOException {

    ObjectNode eventNode = MAPPER.createObjectNode();
    eventNode.put("@timestamp", ISO_DATETIME_TIME_ZONE_FORMAT_WITH_MILLIS.format(event.getTimeStamp()));
    eventNode.put("message", event.getFormattedMessage());
    eventNode.put("tags", createTags(event));
    eventNode.put("thread_name", event.getThreadName());
    eventNode.put("logger_name", event.getLoggerName());
    eventNode.put("level", event.getLevel().toString());
    eventNode.put("level_value", event.getLevel().toInt());
    if (isIncludeCallerInfo()) {
        StackTraceElement callerData = extractCallerData(event);
        eventNode.put("caller_class_name", callerData.getClassName());
        eventNode.put("caller_method_name", callerData.getMethodName());
        eventNode.put("caller_file_name", callerData.getFileName());
        eventNode.put("caller_line_number", callerData.getLineNumber());
    }/*from   www .ja  va 2s  .co m*/

    IThrowableProxy throwableProxy = event.getThrowableProxy();
    if (throwableProxy != null) {
        eventNode.put("stack_trace", ThrowableProxyUtil.asString(throwableProxy));
    }

    Context context = getContext();
    if (context != null) {
        addPropertiesAsFields(eventNode, context.getCopyOfPropertyMap());
    }
    addPropertiesAsFields(eventNode, event.getMDCPropertyMap());

    write(MAPPER.writeValueAsBytes(eventNode), outputStream);
    write(CoreConstants.LINE_SEPARATOR, outputStream);

    if (isImmediateFlush()) {
        outputStream.flush();
    }

}

From source file:org.gradle.test.fixtures.file.AbstractTestDirectoryProvider.java

private String determinePrefix() {
    StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().endsWith("Test") || element.getClassName().endsWith("Spec")) {
            return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test";
        }/*from  w w w .j a  v a 2 s  . co m*/
    }
    return "unknown-test-class";
}