Skip to content

Commit

Permalink
Simplify logging when no ContextManagers are found.
Browse files Browse the repository at this point in the history
Signed-off-by: Sjoerd Talsma <sjoerdtalsma@users.noreply.github.com>
  • Loading branch information
sjoerdtalsma committed Nov 8, 2024
1 parent e17814e commit 7932f71
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ public static nl.talsmasoftware.context.api.ContextSnapshot createContextSnapsho
Timers.timed(System.nanoTime() - managerStart, manager.getClass(), "getActiveContext.exception");
}
}
if (managerStart == null) {
NoContextManagersFound noContextManagersFound = new NoContextManagersFound();
LOGGER.log(Level.INFO, noContextManagersFound.getMessage(), noContextManagersFound);
final ContextSnapshotImpl result = new ContextSnapshotImpl(managers, values);
if (managerStart == null && LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(result + " was created but no ContextManagers were found! "
+ " Thead=" + Thread.currentThread()
+ ", ContextClassLoader=" + Thread.currentThread().getContextClassLoader());
}
ContextSnapshotImpl result = new ContextSnapshotImpl(managers, values);
Timers.timed(System.nanoTime() - start, ContextManagers.class, "createContextSnapshot");
return result;
}
Expand Down Expand Up @@ -139,9 +140,10 @@ public static void clearActiveContexts() {
Timers.timed(System.nanoTime() - managerStart, manager.getClass(), "clear.exception");
}
}
if (managerStart == null) {
NoContextManagersFound noContextManagersFound = new NoContextManagersFound();
LOGGER.log(Level.INFO, noContextManagersFound.getMessage(), noContextManagersFound);
if (managerStart == null && LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("No ContextManagers were cleared because none were found! "
+ " Thead=" + Thread.currentThread()
+ ", ContextClassLoader=" + Thread.currentThread().getContextClassLoader());
}
Timers.timed(System.nanoTime() - start, ContextManagers.class, "clearActiveContexts");
}
Expand Down Expand Up @@ -300,18 +302,7 @@ public void close() {

@Override
public String toString() {
return "ReactivatedContext{size=" + reactivated.size() + '}';
}
}

/**
* Exception that we don't actually throw, but it helps track the issue if we log it including the stacktrace.
*/
private static class NoContextManagersFound extends RuntimeException {
private NoContextManagersFound() {
super("Context snapshot was created but no ContextManagers were found!"
+ " Thread=" + Thread.currentThread()
+ ", ContextClassLoader=" + Thread.currentThread().getContextClassLoader());
return "ContextSnapshot.Reactivation{size=" + reactivated.size() + '}';
}
}
}

0 comments on commit 7932f71

Please sign in to comment.