Example usage for java.lang StackTraceElement toString

List of usage examples for java.lang StackTraceElement toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this stack trace element.

Usage

From source file:com.jkoolcloud.tnt4j.utils.Utils.java

/**
 * Gets resolved name of the method that triggered the operation using
 * current stack frame./*from w w w  .j a v a 2s. c  o m*/
 *
 * @param marker
 *            class marker to be used to locate the stack frame
 * @param offset
 *            offset from the located stack frame (must be >= 0)
 * @return name triggering operation
 */
public static String getMethodNameFromStack(String marker, int offset) {
    StackTraceElement item = Utils.getStackFrame(marker, offset);
    return item.toString();
}

From source file:serposcope.controllers.admin.AdminController.java

public Result stackdump(Context context) {

    return Results.contentType("text/plain").render((ctx, res) -> {
        ResponseStreams responseStreams = context.finalizeHeaders(res);
        try (PrintWriter writer = new PrintWriter(responseStreams.getOutputStream());) {
            final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
            final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
            for (ThreadInfo threadInfo : threadInfos) {
                writer.append('"');
                writer.append(threadInfo.getThreadName());
                writer.append("\" ");
                final Thread.State state = threadInfo.getThreadState();
                writer.append("\n   java.lang.Thread.State: ");
                writer.append(state.toString());
                final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
                for (final StackTraceElement stackTraceElement : stackTraceElements) {
                    writer.append("\n        at ");
                    writer.append(stackTraceElement.toString());
                }/*from   w  w w  .  j  av a 2 s. c  om*/
                writer.println("\n");
            }
        } catch (IOException ex) {
            LOG.error("stackdump", ex);
        }
    });
}

From source file:com.jkoolcloud.tnt4j.utils.Utils.java

/**
 * Gets resolved name of the method that triggered the operation using
 * current stack frame.//from  w  w  w  .  j  av a  2 s .  co m
 *
 * @param classMarker
 *            class marker to be used to locate the stack frame
 * @return name triggering operation
 */
public static String getMethodNameFromStack(Class<?> classMarker) {
    StackTraceElement item = Utils.getStackFrame(classMarker.getName(), 0);
    return item.toString();
}

From source file:org.apache.ode.utils.LoggingConnectionWrapper.java

public PreparedStatement prepareStatement(String sql) throws SQLException {
    if (shouldPrint())
        print("prepareStmt: " + sql);
    if (sql.indexOf("ODE_SCOPE") > 0) {
        for (StackTraceElement traceElement : Thread.currentThread().getStackTrace()) {
            print(traceElement.toString());
        }/*from   w  w w .  j a va  2 s  .  co m*/
    }
    return new LoggingStatementWrapper(_conn.prepareStatement(sql), _log);
}

From source file:com.jkoolcloud.tnt4j.utils.Utils.java

/**
 * Gets resolved name of the method that triggered the operation using
 * current stack frame.//  www. j av a  2  s. c  o  m
 *
 * @param opName
 *            operation name
 * @return name triggering operation
 */
public static String getMethodNameFromStack(String opName) {
    if (!opName.startsWith(OP_STACK_MARKER_PREFIX)) {
        return opName;
    } else {
        String marker = opName.substring(1);
        String[] pair = marker.split(":");
        int offset = pair.length == 2 ? Integer.parseInt(pair[1]) : 0;
        StackTraceElement item = Utils.getStackFrame(pair[0], offset);
        return item.toString();
    }
}

From source file:org.apache.log4j.layout.Log4j1XmlLayout.java

private void formatTo(final LogEvent event, final StringBuilder buf) {
    // We yield to the \r\n heresy.

    buf.append("<log4j:event logger=\"");
    buf.append(Transform.escapeHtmlTags(event.getLoggerName()));
    buf.append("\" timestamp=\"");
    buf.append(event.getTimeMillis());/*w w w  .  j  av  a 2s.  com*/
    buf.append("\" level=\"");
    buf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel())));
    buf.append("\" thread=\"");
    buf.append(Transform.escapeHtmlTags(event.getThreadName()));
    buf.append("\">\r\n");

    buf.append("<log4j:message><![CDATA[");
    // Append the rendered message. Also make sure to escape any existing CDATA sections.
    Transform.appendEscapingCData(buf, event.getMessage().getFormattedMessage());
    buf.append("]]></log4j:message>\r\n");

    List<String> ndc = event.getContextStack().asList();
    if (!ndc.isEmpty()) {
        buf.append("<log4j:NDC><![CDATA[");
        Transform.appendEscapingCData(buf, StringUtils.join(ndc, ' '));
        buf.append("]]></log4j:NDC>\r\n");
    }

    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
    Throwable thrown = event.getThrown();
    if (thrown != null) {
        buf.append("<log4j:throwable><![CDATA[");
        buf.append(thrown.toString());
        buf.append("\r\n");
        for (StackTraceElement element : thrown.getStackTrace()) {
            Transform.appendEscapingCData(buf, "\tat " + element.toString());
            buf.append("\r\n");
        }
        buf.append("]]></log4j:throwable>\r\n");
    }

    if (locationInfo) {
        StackTraceElement source = event.getSource();
        if (source != null) {
            buf.append("<log4j:locationInfo class=\"");
            buf.append(Transform.escapeHtmlTags(source.getClassName()));
            buf.append("\" method=\"");
            buf.append(Transform.escapeHtmlTags(source.getMethodName()));
            buf.append("\" file=\"");
            buf.append(Transform.escapeHtmlTags(source.getFileName()));
            buf.append("\" line=\"");
            buf.append(source.getLineNumber());
            buf.append("\"/>\r\n");
        }
    }

    if (properties) {
        Map<String, String> contextMap = event.getContextMap();
        if (!contextMap.isEmpty()) {
            buf.append("<log4j:properties>\r\n");
            Object[] keys = contextMap.keySet().toArray();
            Arrays.sort(keys);
            for (Object key1 : keys) {
                String key = key1.toString();
                String val = contextMap.get(key);
                if (val != null) {
                    buf.append("<log4j:data name=\"");
                    buf.append(Transform.escapeHtmlTags(key));
                    buf.append("\" value=\"");
                    buf.append(Transform.escapeHtmlTags(val));
                    buf.append("\"/>\r\n");
                }
            }
            buf.append("</log4j:properties>\r\n");
        }
    }

    buf.append("</log4j:event>\r\n\r\n");
}

From source file:com.amalto.core.server.MDMTransaction.java

@Override
public String getCreationStackTrace() {
    String eol = System.getProperty("line.separator"); //$NON-NLS-1$
    StringWriter writer = new StringWriter();
    if (this.creationStackTrace != null) {
        writer.write(/*from   ww w  . j  ava  2  s.  co m*/
                "==================================================================================" + eol); //$NON-NLS-1$
        writer.write("MDM Transaction creation stacktrace:" + eol); //$NON-NLS-1$
        for (StackTraceElement s : this.creationStackTrace) {
            writer.append(s.toString());
            writer.append(eol);
        }
        writer.write(
                "==================================================================================" + eol); //$NON-NLS-1$
    } else {
        writer.append("No creationStackTrace captured at transaction creation. Activate DEBUG on " //$NON-NLS-1$
                + MDMTransaction.class.getCanonicalName() + " to capture future transactions."); //$NON-NLS-1$
    }
    return writer.toString();
}

From source file:com.jkoolcloud.tnt4j.utils.Utils.java

/**
 * Gets resolved name of the method that triggered the operation using
 * current stack frame.//  w  w  w.ja v  a 2  s. c  o  m
 *
 * @param classMarker
 *            class marker to be used to locate the stack frame
 * @param offset
 *            offset from the located stack frame (must be >= 0)
 * @return name triggering operation
 */
public static String getMethodNameFromStack(Class<?> classMarker, int offset) {
    StackTraceElement item = Utils.getStackFrame(classMarker.getName(), offset);
    return item.toString();
}

From source file:com.technophobia.substeps.report.DetailedJsonBuilder.java

private String getStackTrace(IExecutionNode node) {
    String stackTrace = "";

    if (node.getResult().getThrown() != null) {

        final StackTraceElement[] stackTraceElements = node.getResult().getThrown().getStackTrace();

        final StringBuilder buf = new StringBuilder();

        for (final StackTraceElement e : stackTraceElements) {

            buf.append(StringEscapeUtils.escapeHtml4(e.toString().trim())).append("<br/>");
        }//w  w  w .  j a  v a2  s  .  com
        stackTrace = buf.toString();
    }

    return stackTrace;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.environment.UnixFileReadingEnvironmentFactory.java

/**
 * Scan the setenv.sh file one time, gathering a symbol table built out of "variable=value" lines. Then look for two
 * important values: JAVA_HOME and JVM_OPTS.
 *//*from  www  .j av  a  2  s .c o m*/
public Environment create(ConfigResponse config) throws PluginException {
    try {
        Environment environment = new Environment();
        if (new File(Metric.decode(config.getValue("installpath")) + "/bin/setenv.sh").exists()) {
            String envFile = Metric.decode(config.getValue("installpath")) + "/bin/setenv.sh";

            Map<String, String[]> symbolTable = extractPropertyMapping(envFile);
            Set<String> jvmOptsValues = new LinkedHashSet<String>();
            expandValue(symbolTable, "JVM_OPTS", jvmOptsValues);
            JvmOptions combJvmOptions = jvmOptionsConverter.convert(new ArrayList<String>(jvmOptsValues));
            environment.setJvmOptions(combJvmOptions);
            Set<String> javaHome = new LinkedHashSet<String>();
            expandValue(symbolTable, "JAVA_HOME", javaHome);

            environment.setJavaHome(collectionToSpaceDelimitedString(javaHome));
        }
        return environment;
    } catch (IOException e2) {
        for (StackTraceElement elem : e2.getStackTrace()) {
            log.info(elem.toString());
        }
        throw new PluginException(
                "Unable to read existing tc Runtime configuration.  Cause: " + e2.getMessage());
    } catch (Exception e) {
        log.error("Received " + e.getMessage());
        e.printStackTrace();
        throw new PluginException(
                "Unable to read existing tc Runtime configuration.  Cause: " + e.getMessage());
    }
}