[logback-dev] [JIRA] Commented: (LBCLASSIC-31) Avoid printing stack traces under certain conditions

Robert Elliot (JIRA) noreply-jira at qos.ch
Thu Nov 6 00:59:21 CET 2008


    [ http://jira.qos.ch/browse/LBCLASSIC-31?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10879#action_10879 ] 

Robert Elliot commented on LBCLASSIC-31:
----------------------------------------

Sorry, just worked it out - most of the time you would like just the message, but occasionally you might want to see the stack trace too.

Have you considered:

if (!logger.isDebugEnabled()) {
    logger.info("message");
} else {
    logger.debug("message", e);
}

It's a bit long winded, but it has the effect of allowing you to print the stack trace for debug and not for info, allowing you to choose how much appears in the log.

> Avoid printing stack traces under certain conditions
> ----------------------------------------------------
>
>                 Key: LBCLASSIC-31
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-31
>             Project: logback-classic
>          Issue Type: Improvement
>          Components: Other
>    Affects Versions: unspecified
>         Environment: Operating System: Windows
> Platform: PC
>            Reporter: Ceki Gulcu
>            Assignee: Logback dev list
>            Priority: Minor
>
> It would be useful if under certain very specific conditions, logback avoided printing stack traces.
> In particular, in server applications IOEXceptions are thrown under normal conditions, such as when the client closes its connection to the server.
> Typical code would look like:
>   try {
>         event = (AuditEvent) ois.readObject();
>   } catch (java.io.EOFException e) {
>         logger.info("Caught java.io.EOFException closing connection.", e);
>         break;
>   } catch (IOException e) {
>         logger.info("Caught java.io.IOException: ", e);
>         break;
>   } catch (ClassNotFoundException e) {
>        logger.error("Unexpected ClassNotFoundException.", e);
>        writeResponse(e);
>        break;
>   }
> Most of the time we would like to avoid printing the stack trace for the two exceptions but not the third.
> Possible solution:
>  Marker ignoreST = MarkerFactgory.getMarker("IGNORE_STACK_TRACE"); 
>  logger.info(ignoreST, "Caught java.io.EOFException closing connection.", e);
> Note that even if most of the time we would like to avoid printing the stack trace, it should still be possible to allow st printing by overriding some parameter.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list