Class StackTrace
java.lang.Object
com.github.toolarium.common.stacktrace.StackTrace
The StackInfo class is a collection of static methods to allow users to quickly determine the call stack.
This class makes it possible to determine what class called a method and what text files and line numbers
resulted in stack calls. The StackInfo calls will not appear in return string.
By calling the method getTrace a 2D-String-Array is returned.
-
Field Summary
FieldsModifier and TypeFieldDescriptionDefault Stacktrace exclues -
Method Summary
Modifier and TypeMethodDescriptionstatic StackTraceElement[]filterStackTrace(StackTraceElement[] elements) Filter the given trace elements as stack tracestatic StackTraceElement[]filterStackTrace(StackTraceElement[] elements, List<String> filteredClassNames) Filter the given trace elements as stack tracestatic StringCreate the current stack tracestatic StringgetStackTrace(int traceSize) Create the current stack tracestatic StringgetStackTrace(StackTraceElement[] elements) Prepares the given trace elements as stack tracestatic StringgetStackTrace(StackTraceElement[] elements, List<String> filteredClassNames) Prepares the given trace elements as stack tracestatic StringgetStackTrace(StackTraceElement[] elements, List<String> filteredClassNames, String header) Prepares the given trace elements as stack tracestatic StringgetStackTrace(StackTraceElement[] elements, List<String> filteredClassNames, String header, String newline) Prepares the given trace elements as stack tracestatic StackTraceElement[]Parse the stack tracestatic StackTraceElement[]getStackTraceElements(int numberOfLastElements) Parse the stack tracestatic StackTraceElement[]getStackTraceElements(int startIndex, int numberOfLastElements) Parse the stack tracestatic StackTraceElementparseStackTraceElement(String line) Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling classstatic StackTraceElement[]parseStackTraceElements(String callStack, int startIndex, int traceSize) Parse the stack trace into the desired two dimensional stringstatic StackTraceElement[]parseStackTraceElements(Throwable t, int startTrace, int traceSize) Parse the stack trace into the desired two dimensional stringstatic String[]parseStackTraceLine(String line) Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling classstatic voidprocessStackTrace(Consumer<String> consumer) Process the current stack tracestatic voidprocessStackTrace(Consumer<String> consumer, int traceSize) Process the current stack tracestatic voidprocessStackTrace(Consumer<String> consumer, List<String> filteredClassNames) Create the current stack tracestatic voidCreate the current stack tracestatic voidprocessStackTrace(Consumer<String> consumer, List<String> filteredClassNames, String header, int traceSize) Create the current stack tracestatic voidprocessStackTrace(Consumer<String> consumer, List<String> filteredClassNames, String header, String newline, int traceSize) Create the current stack trace
-
Field Details
-
DEFAULT_EXCLUDES
Default Stacktrace exclues
-
-
Method Details
-
getStackTraceElements
Parse the stack trace- Returns:
- an array with stack trace elements.
-
getStackTraceElements
Parse the stack trace- Parameters:
numberOfLastElements- the number of the last elements in stack trace- Returns:
- an array with stack trace elements.
-
getStackTraceElements
Parse the stack trace- Parameters:
startIndex- the start indexnumberOfLastElements- the number of the last elements in stack trace- Returns:
- an array with stack trace elements.
-
getStackTrace
Create the current stack trace- Returns:
- the stack trace
-
getStackTrace
Create the current stack trace- Parameters:
traceSize- the size of the stack trace (default -1)- Returns:
- the stack trace
-
getStackTrace
Prepares the given trace elements as stack trace- Parameters:
elements- the elements- Returns:
- the prepared stack trace
-
getStackTrace
Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filtered- Returns:
- the prepared stack trace
-
getStackTrace
public static String getStackTrace(StackTraceElement[] elements, List<String> filteredClassNames, String header) Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filteredheader- the header- Returns:
- the prepared stack trace
-
getStackTrace
public static String getStackTrace(StackTraceElement[] elements, List<String> filteredClassNames, String header, String newline) Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filteredheader- the headernewline- the newline- Returns:
- the prepared stack trace
-
processStackTrace
Process the current stack trace- Parameters:
consumer- the consumer
-
processStackTrace
Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filtered
-
processStackTrace
Process the current stack trace- Parameters:
consumer- the consumertraceSize- the size of the stack trace (default -1)
-
processStackTrace
public static void processStackTrace(Consumer<String> consumer, List<String> filteredClassNames, String header) Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the header
-
processStackTrace
public static void processStackTrace(Consumer<String> consumer, List<String> filteredClassNames, String header, int traceSize) Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the headertraceSize- the size of the stack trace (default -1)
-
processStackTrace
public static void processStackTrace(Consumer<String> consumer, List<String> filteredClassNames, String header, String newline, int traceSize) Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the headernewline- the newlinetraceSize- the size of the stack trace (default -1)
-
filterStackTrace
Filter the given trace elements as stack trace- Parameters:
elements- the elements- Returns:
- the prepared stack trace
-
filterStackTrace
public static StackTraceElement[] filterStackTrace(StackTraceElement[] elements, List<String> filteredClassNames) Filter the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filtered- Returns:
- the prepared stack trace
-
parseStackTraceElements
public static StackTraceElement[] parseStackTraceElements(Throwable t, int startTrace, int traceSize) throws IOException Parse the stack trace into the desired two dimensional string- Parameters:
t- the exceptionstartTrace- the start of the trace (default 2)traceSize- the stack trace size (default -1)- Returns:
- a formated two dimensional string:
Each row representate a call on the stack and the columns
are formated like below:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
- Throws:
IOException- in case of error
-
parseStackTraceElements
public static StackTraceElement[] parseStackTraceElements(String callStack, int startIndex, int traceSize) Parse the stack trace into the desired two dimensional string- Parameters:
callStack- the stack trace to parsestartIndex- the start of the trace (default 2)traceSize- the stack trace size (default -1)- Returns:
- a formated two dimensional string:
Each row representate a call on the stack and the columns
are formated like below:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
-
parseStackTraceElement
Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling class- Parameters:
line- a line from the stack trace- Returns:
- a stack trace element
-
parseStackTraceLine
Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling class- Parameters:
line- a line from the stack trace- Returns:
- a formated stack trace array:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
-