Example usage for java.lang StackTraceElement getFileName

List of usage examples for java.lang StackTraceElement getFileName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getFileName.

Prototype

public String getFileName() 

Source Link

Document

Returns the name of the source file containing the execution point represented by this stack trace element.

Usage

From source file:io.teak.sdk.Raven.java

public void reportException(Throwable t) {
    if (t == null) {
        return;/*from www . j  a v a2s.c  o m*/
    }

    HashMap<String, Object> additions = new HashMap<>();
    ArrayList<Object> exceptions = new ArrayList<>();
    HashMap<String, Object> exception = new HashMap<>();

    exception.put("type", t.getClass().getSimpleName());
    exception.put("value", t.getMessage());
    exception.put("module", t.getClass().getPackage().getName());

    HashMap<String, Object> stacktrace = new HashMap<>();
    ArrayList<Object> stackFrames = new ArrayList<>();

    StackTraceElement[] steArray = t.getStackTrace();
    for (int i = steArray.length - 1; i >= 0; i--) {
        StackTraceElement ste = steArray[i];
        HashMap<String, Object> frame = new HashMap<>();

        frame.put("filename", ste.getFileName());

        String method = ste.getMethodName();
        if (method.length() != 0) {
            frame.put("function", method);
        }

        int lineno = ste.getLineNumber();
        if (!ste.isNativeMethod() && lineno >= 0) {
            frame.put("lineno", lineno);
        }

        String module = ste.getClassName();
        frame.put("module", module);

        boolean in_app = true;
        if (module.startsWith("android.") || module.startsWith("java.") || module.startsWith("dalvik.")
                || module.startsWith("com.android.")) {
            in_app = false;
        }

        frame.put("in_app", in_app);

        stackFrames.add(frame);
    }
    stacktrace.put("frames", stackFrames);

    exception.put("stacktrace", stacktrace);

    exceptions.add(exception);
    additions.put("exception", exceptions);

    try {
        Report report = new Report(t.getMessage(), Level.ERROR, additions);
        report.sendToService();
    } catch (Exception e) {
        Log.e(LOG_TAG, "Unable to report Teak SDK exception. " + Log.getStackTraceString(t) + "\n"
                + Log.getStackTraceString(e));
    }
}

From source file:net.logstash.logback.LogstashFormatter.java

private void createFields(ILoggingEvent event, Context context, ObjectNode eventNode) {
    final Marker marker = event.getMarker();

    eventNode.put("logger_name", event.getLoggerName());
    eventNode.put("thread_name", event.getThreadName());
    eventNode.put("level", event.getLevel().toString());
    eventNode.put("level_value", event.getLevel().toInt());

    if (includeCallerInfo) {
        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  w w  w .j  a v a2s. c  o m

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

    if (context != null) {
        addPropertiesAsFields(eventNode, context.getCopyOfPropertyMap());
    }
    if (marker != null && marker.contains("JSON")) {
        eventNode.put("json_message", getJsonNode(event));
    }
    addPropertiesAsFields(eventNode, event.getMDCPropertyMap());

    addCustomFields(eventNode);

}

From source file:com.bstek.dorado.idesupport.resolver.RobotResolver.java

protected void assembleError(Document document, Element responseElement, Exception error) {
    String message = error.getMessage();
    if (message == null) {
        message = error.getClass().getSimpleName();
    }/*  w  w  w . j  a v  a 2s.  c om*/
    Element messageElement = document.createElement("Message");
    messageElement.appendChild(document.createTextNode(message));
    responseElement.appendChild(messageElement);

    Element stackTraceElement = document.createElement("StackTrace");
    responseElement.appendChild(stackTraceElement);

    StackTraceElement[] stackTrace = error.getStackTrace();
    for (StackTraceElement ste : stackTrace) {
        Element element = document.createElement("Element");
        element.setAttribute("className", ste.getClassName());
        element.setAttribute("methodName", ste.getMethodName());
        element.setAttribute("fileName", ste.getFileName());
        element.setAttribute("lineNumber", String.valueOf(ste.getLineNumber()));
        stackTraceElement.appendChild(element);
    }
}

From source file:io.coala.log.CoalaLog4jLogger.java

/**
 * @return//ww w  .  ja  v a 2 s . c o  m
 */
protected String getMethodAffix() {
    int i = 4;
    StackTraceElement elem = Thread.currentThread().getStackTrace()[i];
    while (isLoggingPackage(elem.getClassName()))
        elem = Thread.currentThread().getStackTrace()[++i];
    return String.format(METHOD_AFFIX_FORMAT, elem.getClassName(), elem.getMethodName(), elem.getFileName(),
            elem.getLineNumber());
}

From source file:com.zimbra.common.service.ServiceException.java

/**
 * This is for exceptions that are usually not logged and thus need to include an unique "label"
 * in the exception id so the thrown(or instantiation) location can be identified by the exception id alone
 * (without referencing the log - the stack won't be in the log).
 *
 * @param callSite call site of the stack where the caller wants to include in the exception id
 *//*from   ww w  .j a  va 2s.co m*/
public void setIdLabel(StackTraceElement callSite) {
    String fileName = callSite.getFileName();
    int i = fileName.lastIndexOf('.');
    if (i != -1)
        fileName = fileName.substring(0, i);

    mId = mId + ":" + fileName + callSite.getLineNumber();
}

From source file:org.apromore.service.pql.impl.PQLServiceImpl.java

public List<String> runAPQLQuery(String queryPQL, List<String> IDs, String userID) {
    //Set<String> idNets=new HashSet<>();
    List<String> results = Collections.emptyList();
    IPQLAPI api = pqlBean.getApi();//w  ww.  j  ava  2  s .c o m
    LOGGER.error("-----------PQLAPI: " + api);
    LOGGER.error("----------- query: " + queryPQL);
    LOGGER.error("-----------   IDs: " + IDs);
    LOGGER.error("-----------  user: " + userID);
    try {
        PQLQueryResult pqlQueryResult = api.query(queryPQL, new HashSet<>(IDs));
        if (pqlQueryResult.getNumberOfParseErrors() != 0) {
            results = pqlQueryResult.getParseErrorMessages();
        } else {//risultati
            LOGGER.error("-----------IDS PQLServiceImpl" + IDs);
            map = pqlQueryResult.getTaskMap();
            LinkedList<PQLTask> tasks = new LinkedList<>(map.values());
            /*
                            idNets=new HashSet<>(IDs);
                            idNets=api.checkLastQuery(idNets);
                            results.addAll(idNets);
            */
            results = new LinkedList<>(pqlQueryResult.getSearchResults());
            LOGGER.error("-----------QUERYAPQL ESATTA " + results);
        }
    } catch (Exception e) {
        LOGGER.error("-----------ERRORRE: " + e.toString());
        for (StackTraceElement ste : e.getStackTrace())
            LOGGER.info("ERRORE6: " + ste.getClassName() + " " + ste.getMethodName() + " " + ste.getLineNumber()
                    + " " + ste.getFileName());
    }
    return results;
}

From source file:com.bstek.dorado.view.resolver.ViewServiceResolver.java

/**
 * @param jsonBuilder//from  w  w  w  .  ja v  a  2 s . co m
 * @param e
 */
protected void outputException(JsonBuilder jsonBuilder, Throwable throwable) {
    while (throwable.getCause() != null) {
        throwable = throwable.getCause();
    }

    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getSimpleName();
    }

    try {
        jsonBuilder.object(); // TODO: ?JSONBuilder?
        jsonBuilder.key("exceptionType").value("JavaException").key("message").value(message).key("stackTrace");
        jsonBuilder.array();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            jsonBuilder.value(stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '('
                    + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')');
        }
        jsonBuilder.endArray();
        jsonBuilder.endObject();
    } catch (Exception e) {
        // ignore e!!!
        throwable.printStackTrace();
    }
}

From source file:net.logstash.logback.composite.loggingevent.CallerDataJsonProvider.java

@Override
public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
    StackTraceElement callerData = extractCallerData(event);
    if (callerData == null) {
        return;/*from  w  w w  .  j a  v a  2  s  .c om*/
    }
    if (getFieldName() != null) {
        generator.writeObjectFieldStart(getFieldName());
    }
    JsonWritingUtils.writeStringField(generator, classFieldName, callerData.getClassName());
    JsonWritingUtils.writeStringField(generator, methodFieldName, callerData.getMethodName());
    JsonWritingUtils.writeStringField(generator, fileFieldName, callerData.getFileName());
    JsonWritingUtils.writeNumberField(generator, lineFieldName, callerData.getLineNumber());
    if (getFieldName() != null) {
        generator.writeEndObject();
    }
}

From source file:minium.script.rhinojs.RhinoEngine.java

protected StackTraceElement[] process(StackTraceElement[] stackTrace) {
    List<StackTraceElement> processed = Lists.newArrayList();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().startsWith("org.mozilla.javascript.gen") && element.getLineNumber() != -1) {
            String fileName = null;
            File file = new File(element.getFileName());
            if (file.exists() && file.isFile()) {
                fileName = file.getAbsolutePath();
            }/*from ww  w  .  ja  v a2 s .c  o  m*/
            if (fileName == null)
                fileName = element.getFileName();
            processed.add(new StackTraceElement(element.getClassName(), element.getMethodName(), fileName,
                    element.getLineNumber()));
        }
    }
    return processed.toArray(new StackTraceElement[processed.size()]);
}

From source file:org.jtrfp.trcl.TriangleList.java

private void setupVertex(int vIndex, int gpuTVIndex, int triangleIndex, TextureDescription td)
        throws ExecutionException, InterruptedException {
    final int numFrames = getPrimitives().length;
    final Triangle t = triangleAt(0, triangleIndex);
    final Vector3D pos = t.getVertices()[vIndex].getPosition();
    final TriangleVertexWindow vw = (TriangleVertexWindow) getMemoryWindow();
    ////////////////////// V E R T E X //////////////////////////////
    if (numFrames == 1) {
        vw.x.set(gpuTVIndex, (short) applyScale(pos.getX()));
        vw.y.set(gpuTVIndex, (short) applyScale(pos.getY()));
        vw.z.set(gpuTVIndex, (short) applyScale(pos.getZ()));
        final Vector3D normal = t.getVertices()[vIndex].getNormal();
        vw.normX.set(gpuTVIndex, (byte) (normal.getX() * 127));
        vw.normY.set(gpuTVIndex, (byte) (normal.getY() * 127));
        vw.normZ.set(gpuTVIndex, (byte) (normal.getZ() * 127));
    } else {//ww w .  j a v a2 s.  co m
        float[] xFrames = new float[numFrames];
        float[] yFrames = new float[numFrames];
        float[] zFrames = new float[numFrames];
        float[] nxFrames = new float[numFrames];
        float[] nyFrames = new float[numFrames];
        float[] nzFrames = new float[numFrames];
        for (int i = 0; i < numFrames; i++) {
            xFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getX());
        }
        xyzAnimator.addFrames(xFrames);

        for (int i = 0; i < numFrames; i++) {
            yFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getY());
        }
        xyzAnimator.addFrames(yFrames);

        for (int i = 0; i < numFrames; i++) {
            zFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getZ());
        }
        xyzAnimator.addFrames(zFrames);

        for (int i = 0; i < numFrames; i++) {
            nxFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getX() * 127);
        }
        xyzAnimator.addFrames(nxFrames);

        for (int i = 0; i < numFrames; i++) {
            nyFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getY() * 127);
        }
        xyzAnimator.addFrames(nyFrames);

        for (int i = 0; i < numFrames; i++) {
            nzFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getZ() * 127);
        }
        xyzAnimator.addFrames(nzFrames);
    } //end else(frames!=1)
      //////////////// T E X T U R E ///////////////////////////
    if (td == null) {
        System.err.println("Stack trace of triangle creation below. NullPointerException follows.");
        for (StackTraceElement el : t.getCreationStackTrace()) {
            System.err.println("\tat " + el.getClassName() + "." + el.getMethodName() + "(" + el.getFileName()
                    + ":" + el.getLineNumber() + ")");
        } //end for(stackTrace)
        throw new NullPointerException("Texture for triangle in " + debugName + " intolerably null.");
    }
    if (td instanceof Texture) {// Static texture
        final int sideScalar = ((Texture) td).getSideLength() - 1;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            uvAnimator.setDebugName(debugName + ".uvAnimator");
            for (int i = 0; i < numFrames; i++) {
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final int textureID = ((Texture) td).getTexturePage();
        vw.textureIDLo.set(gpuTVIndex, (byte) (textureID & 0xFF));
        vw.textureIDMid.set(gpuTVIndex, (byte) ((textureID >> 8) & 0xFF));
        vw.textureIDHi.set(gpuTVIndex, (byte) ((textureID >> 16) & 0xFF));
    } // end if(Texture)
    if (td instanceof AnimatedTexture) {//Animated texture
        final AnimatedTexture at = (AnimatedTexture) td;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            for (int i = 0; i < numFrames; i++) {
                final int sideScalar = at.getFrames()[i].getSideLength() - 1;
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            final int sideScalar = at.getFrames()[0].getSideLength() - 1;
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final TexturePageAnimator texturePageAnimator = new TexturePageAnimator(at, vw, gpuTVIndex);
        texturePageAnimator.setDebugName(debugName + ".texturePageAnimator");
        getModel().addTickableAnimator(texturePageAnimator);
    } //end if(animated texture)
}