QOS.ch JIRA

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • logback-classic
  • LBCLASSIC-217

Exception stack trace printing starting from root cause

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.9.22
  • Fix Version/s: 0.9.30
  • Component/s: None
  • Labels:
    None

Description

A typical exception in multi-tier application looks similar to this:

com.acme.BusinessException: Can't process request
at ...
at ...
Caused by: com.acme.dao.PersistenceException: Can't access database
at ...
at ...
... 49 common frames omitted
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Unable to locate datasource
at ...
at ...
... 65 common frames omitted
Caused by: java.net.UnknownHostException: Unknown host localhostt
at ...
at ...
... 84 common frames omitted

The deeper exception, the more specific information it gives. Typically the last "Caused by" is the most interesting one. So it seems like reversing the order in which the exceptions are thrown (from most specific to consecutive, less specific wrappers) might be more intuitive:

java.net.UnknownHostException: Unknown host localhostt
at ...
at ...
Wrapped by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Unable to connect to the database
at ...
at ...
Wrapped by: com.acme.dao.PersistenceException: Can't access database
at ...
at ...
Wrapped by: com.acme.BusinessException: Can't process request
at ...
at ...

It is not only easier to read and follow (business exception is interesting for the end user while the most precise, technical information is for developers and system administrators - so it should be easily accessible in the logs), but also the stack trace isn't mixed. You can read stack frames in exactly the same order as they were executed, no need to jump from one stack trace line to another (see attachment from the real application). This also means that the beginning of the thread is always at the bottom and the line that caused the very first exception - at the top. (look at the attached real exception)

I already implemented this feature by adding RootCauseFirstThrowableProxyConverter extending ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter. It is turned on by appending "%rEx" to the encoder pattern. If you like this feature, I will push the changes (just few classes have changed) into my GitHub fork.
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    wrapped_by_stack_trace.txt
    07/Aug/10 6:14 PM
    13 kB
    Tomasz Nurkiewicz

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
Hide
Permalink
Tomasz Nurkiewicz added a comment - 15/Aug/10 8:11 PM
I pushed rough implementation of this feature, including some smoke unit tests:

http://github.com/nurkiewicz/logback/commit/679fcda1a4a3e67fcb2604e47c7fa0de2beaf6bd
http://github.com/nurkiewicz/logback/commit/869b85c1362ba5e60d53e92d1480609d906f0c20
Show
Tomasz Nurkiewicz added a comment - 15/Aug/10 8:11 PM I pushed rough implementation of this feature, including some smoke unit tests: http://github.com/nurkiewicz/logback/commit/679fcda1a4a3e67fcb2604e47c7fa0de2beaf6bd http://github.com/nurkiewicz/logback/commit/869b85c1362ba5e60d53e92d1480609d906f0c20
Hide
Permalink
Tomasz Nurkiewicz added a comment - 18/Aug/11 6:54 PM
Any news on this issue?
Show
Tomasz Nurkiewicz added a comment - 18/Aug/11 6:54 PM Any news on this issue?
Hide
Permalink
Ceki Gulcu added a comment - 18/Aug/11 11:39 PM
Looks good.
Show
Ceki Gulcu added a comment - 18/Aug/11 11:39 PM Looks good.
Hide
Permalink
Ceki Gulcu added a comment - 20/Sep/11 10:09 PM - edited
I get 404 on both github links listed above.

Anyway, I am currently looking into https://github.com/nurkiewicz/logback/commit/a21ed3cc6fc72da5b3c2f54e6b61752ff1d0100f which seems to be the relevant commit. However, it lacks documentation for rEx/rootException under [1]. Care to add it? The source is under logback-site/src/site/pages/manual/layouts.html. As I plan to make a release soon, please let me know if you want to take a shot at the docs. Otherwise, I'll handle it.

[1] http://logback.qos.ch/manual/layouts.html#conversionWord
Show
Ceki Gulcu added a comment - 20/Sep/11 10:09 PM - edited I get 404 on both github links listed above. Anyway, I am currently looking into https://github.com/nurkiewicz/logback/commit/a21ed3cc6fc72da5b3c2f54e6b61752ff1d0100f which seems to be the relevant commit. However, it lacks documentation for rEx/rootException under [1]. Care to add it? The source is under logback-site/src/site/pages/manual/layouts.html. As I plan to make a release soon, please let me know if you want to take a shot at the docs. Otherwise, I'll handle it. [1] http://logback.qos.ch/manual/layouts.html#conversionWord
Hide
Permalink
Ceki Gulcu added a comment - 20/Sep/11 10:40 PM - edited
Just applied https://github.com/nurkiewicz/logback/commit/a21ed as [1] on my repo. I also wrote the relevant documentation [2]. Please review if you can.

[1] https://github.com/ceki/logback/commit/f0b1a778e9
[2] https://github.com/ceki/logback/commit/b1e595bcf4
Show
Ceki Gulcu added a comment - 20/Sep/11 10:40 PM - edited Just applied https://github.com/nurkiewicz/logback/commit/a21ed as [1] on my repo. I also wrote the relevant documentation [2]. Please review if you can. [1] https://github.com/ceki/logback/commit/f0b1a778e9 [2] https://github.com/ceki/logback/commit/b1e595bcf4
Hide
Permalink
Tomasz Nurkiewicz added a comment - 24/Sep/11 10:05 AM
Thank you for applying this feature! Sorry for broken links, don't know how this happened. I opened a trivial pull request (Correct 0.9.30 version in @since tag: https://github.com/ceki/logback/pull/28). If you care, I also blogged about this feature: http://nurkiewicz.blogspot.com/2011/09/logging-exceptions-root-cause-first.html
Show
Tomasz Nurkiewicz added a comment - 24/Sep/11 10:05 AM Thank you for applying this feature! Sorry for broken links, don't know how this happened. I opened a trivial pull request (Correct 0.9.30 version in @since tag: https://github.com/ceki/logback/pull/28). If you care, I also blogged about this feature: http://nurkiewicz.blogspot.com/2011/09/logging-exceptions-root-cause-first.html

People

  • Assignee:
    Logback dev list
    Reporter:
    Tomasz Nurkiewicz
Vote (0)
Watch (1)

Dates

  • Created:
    07/Aug/10 6:11 PM
    Updated:
    24/Sep/11 10:05 AM
    Resolved:
    20/Sep/11 11:52 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for logback. Try JIRA - bug tracking software for your team.