Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/647#discussion_r113901893
--- Diff:
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/DefaultExceptionMapper.java
---
@@ -120,6 +121,32 @@ public Response toResponse(Throwable throwable1) {
return rb.build().asResponse(Status.INTERNAL_SERVER_ERROR,
MediaType.APPLICATION_JSON_TYPE);
}
+ /** Logs full details at trace, unless it is the first time we've seen
this in which case it is debug */
+ @Beta
+ public static void logExceptionDetailsForDebugging(Throwable t) {
+ if (LOG.isDebugEnabled()) {
+ if (firstEncounter(t)) {
+ // include debug trace for everything the first time we
get one
+ LOG.debug("Full details of
"+Entitlements.getEntitlementContext()+" "+t+" (logging debug on first
encounter; subsequent instances will be logged trace)", t);
+ } else if (LOG.isTraceEnabled()) {
+ LOG.trace("Full details of
"+Entitlements.getEntitlementContext()+" "+t, t);
+ }
+ }
+ }
+
+ private static boolean firstEncounter(Throwable t) {
+ Set<Object> record = MutableSet.of();
+ while (true) {
--- End diff --
there is the additional `break` when we find a stack trace element we've
seen before.
i've been caught out by perverse `Throwable` instances with cyclic causal
chains which that catches.
i don't like using `break` but there are times it is simpler. in those
cases i prefer not to mix it with `while (interestingCondition)` syntax to make
it clear that `break` semantics are being used.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---