Skip to content

Commit

Permalink
fix issues/425
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Oct 21, 2024
1 parent 914e8c8 commit fa7c18f
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions slf4j-jdk14/src/main/java/org/slf4j/jul/JDK14LoggerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public final class JDK14LoggerAdapter extends LegacyAbstractLogger implements Lo

transient final java.util.logging.Logger logger;

static int NOT_FOUND = -1;

// WARN: JDK14LoggerAdapter constructor should have only package access so
// that only JDK14LoggerFactory be able to create one.
JDK14LoggerAdapter(java.util.logging.Logger logger) {
Expand Down Expand Up @@ -181,26 +183,10 @@ public void log(Marker marker, String callerFQCN, int slf4jLevelInt, String mess
final private void fillCallerData(String callerFQCN, LogRecord record) {
StackTraceElement[] steArray = new Throwable().getStackTrace();

int selfIndex = -1;
for (int i = 0; i < steArray.length; i++) {
final String className = steArray[i].getClassName();

if (barrierMatch(callerFQCN, className)) {
selfIndex = i;
break;
}
}

int found = -1;
for (int i = selfIndex + 1; i < steArray.length; i++) {
final String className = steArray[i].getClassName();
if (!(barrierMatch(callerFQCN, className))) {
found = i;
break;
}
}
int furthestIndex = findFurthestIndex(callerFQCN, steArray);

if (found != -1) {
if (furthestIndex != NOT_FOUND) {
int found = furthestIndex+1;
StackTraceElement ste = steArray[found];
// setting the class name has the side effect of setting
// the needToInferCaller variable to false.
Expand All @@ -209,7 +195,24 @@ final private void fillCallerData(String callerFQCN, LogRecord record) {
}
}

static String SELF = JDK14LoggerAdapter.class.getName();
// find the furthest index which matches any of the barrier classes
// We assume that the actual caller is at most MAX_SEARCH_DEPTH calls away
private int findFurthestIndex(String callerFQCN, StackTraceElement[] steArray) {

final int maxIndex = Math.min(MAX_SEARCH_DEPTH, steArray.length);
int furthestIndex = NOT_FOUND;

for (int i = 0; i < maxIndex; i++) {
final String className = steArray[i].getClassName();
if (barrierMatch(callerFQCN, className)) {
furthestIndex = i;
}
}
return furthestIndex;
}

static final int MAX_SEARCH_DEPTH = 12;
static String SELF = JDK14LoggerAdapter.class.getName();

static String SUPER = LegacyAbstractLogger.class.getName();
static String SUPER_OF_SUPER = AbstractLogger.class.getName();
Expand Down

0 comments on commit fa7c18f

Please sign in to comment.