Skip to content

Commit

Permalink
Fix double log capture (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Apr 1, 2020
1 parent 64b9585 commit 10d93ac
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
public static class LogMessageAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(
public static boolean methodEnter(
@Advice.This final Logger logger,
@Advice.Argument(1) final Level level,
@Advice.Argument(3) final Message message,
@Advice.Argument(4) final Throwable t) {
Log4jSpans.capture(logger, level, message, t);
// need to track call depth across all loggers in order to avoid double capture when one
// logging framework delegates to another
final boolean topLevel = CallDepthThreadLocalMap.incrementCallDepth("logger") == 0;
if (topLevel) {
Log4jSpans.capture(logger, level, message, t);
}
return topLevel;
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(@Advice.Enter final boolean topLevel) {
if (topLevel) {
CallDepthThreadLocalMap.reset("logger");
}
}
}

Expand Down

0 comments on commit 10d93ac

Please sign in to comment.