Skip to content

Commit

Permalink
Adds the option to print the stack trace of the current Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Mar 12, 2022
1 parent fa7f3dc commit c16f29d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ummisco.gama.annotations/src/ummisco/gama/dev/utils/DEBUG.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* DEBUG.java, in ummisco.gama.annotations, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* DEBUG.java, in ummisco.gama.annotations, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.dev.utils;

Expand All @@ -20,7 +20,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Supplier;
import java.lang.StackWalker;

/**
* A simple and generic debugging/logging class that can be turned on / off on a class basis.
Expand Down Expand Up @@ -449,8 +448,6 @@ public static String PAD(final String string, final int minLength, final char c)
public static String METHOD() {
StackWalker.StackFrame frame = STACK_WALKER.walk(stream1 -> stream1.skip(2).findFirst().orElse(null));
return frame == null ? "no calling method" : frame.getMethodName();
// return String.format("caller: %s#%s, %s", frame.getClassName(), frame.getMethodName(),
// frame.getLineNumber());
}

/**
Expand All @@ -461,8 +458,18 @@ public static String METHOD() {
public static String CALLER() {
StackWalker.StackFrame frame = STACK_WALKER.walk(stream1 -> stream1.skip(2).findFirst().orElse(null));
return frame == null ? "no one" : frame.getClassName();
// return String.format("caller: %s#%s, %s", frame.getClassName(), frame.getMethodName(),
// frame.getLineNumber());
}

/**
* Stack.
*/
public static void STACK() {
LOG(PAD("--- Stack trace ", 80, '-'));
STACK_WALKER.walk(stream1 -> {
stream1.skip(2).forEach(s -> LOG("> " + s));
return null;
});
LINE();
}

}

0 comments on commit c16f29d

Please sign in to comment.