All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.etsy.statsd.profiler.util.StackTraceFormatter Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.etsy.statsd.profiler.util;

import com.google.common.base.Joiner;

import java.util.ArrayList;
import java.util.List;

/**
 * Utility class for formatting stack traces
 *
 * @author Andrew Johnson
 */
public class StackTraceFormatter {
    /**
     * Formats a StackTraceElement as a String, excluding the line number
     *
     * @param element The StackTraceElement to format
     * @return A String representing the given StackTraceElement
     */
    public static String formatStackTraceElement(StackTraceElement element) {
        return String.format("%s-%s-%d", element.getClassName().replace(".", "-"), element.getMethodName(), element.getLineNumber());
    }

    /**
     * Formats an entire stack trace as a String
     *
     * @param stack The stack trace to format
     * @return A String representing the given stack trace
     */
    public static String formatStackTrace(StackTraceElement[] stack) {
        List lines = new ArrayList<>();
        for (StackTraceElement element : stack) {
            lines.add(formatStackTraceElement(element));
        }

        return Joiner.on(".").join(lines);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy