You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2017/04/24 14:27:29 UTC

[GitHub] brooklyn-server pull request #647: better logging of REST exceptions

GitHub user ahgittin opened a pull request:

    https://github.com/apache/brooklyn-server/pull/647

    better logging of REST exceptions

    include the trace on the first encounter of a new type or simply a new place where a type is thrown from;
    subsequent instances won't get the trace but handy when debugging if the first one does

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ahgittin/brooklyn-server rest-error-logging

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/647.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #647
    
----

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #647: better logging of REST exceptions

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/647


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #647: better logging of REST exceptions

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on the issue:

    https://github.com/apache/brooklyn-server/pull/647
  
    This is fine as-is, will merge.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #647: better logging of REST exceptions

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/647#discussion_r113902113
  
    --- 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 --
    
    Interesting, that's a nice guideline, now that you mention it.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #647: better logging of REST exceptions

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/647#discussion_r113234019
  
    --- 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 --
    
    `while (true)` always looks alarming; in this case it may well be fine, as `t = t.getCause()` won't last forever. But why not simply write `while (t != null)` and avoid the `if (t==null) break;`?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #647: better logging of REST exceptions

Posted by ahgittin <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---