qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.97k stars 1.28k forks source link

make it easier to ingest stack traces into logging backends #809

Open zeitlinger opened 4 months ago

zeitlinger commented 4 months ago

Problem

Logging backends, such as Loki, ingest stack traces as one string.

Therefore, it would be good to have an option in the json encoder, to emit stack traces plainly - as a string.

Instead of

"throwable": {
    "className": "java.lang.RuntimeException",
    "message": "test",
    "stepArray": [
      {
        "className": "ch.qos.logback.classic.encoder.JsonEncoderTest",
        "methodName": "withThrowable",
        "fileName": "JsonEncoderTest.java",
        "lineNumber": 251
      },

something like

 "throwable": {
    "className": "java.lang.RuntimeException",
    "message": "test",
    "stackTrace": "java.lang.RuntimeException: test\n\tat ch.qos.lo

Proposed solution

Add a withPlainStackTrace option to the json encoder.

PR: https://github.com/qos-ch/logback/pull/808

zeitlinger commented 4 months ago

@ceki wdyt?

ceki commented 4 months ago

I looked at the code. The changes are reasonable. However, the code which was already rather complex becomes harder to read with your changes.

I think a pluggable strategy for handling the stack trace output format starts to make sense. A default strategy and a "PlainStackTrace" strategy. This should not be hard to put in place. Let me know if you feel comfortable with the idea and making this change.

Also, could your PR be please compressed into a single commit?

zeitlinger commented 4 months ago

Also, could your PR be please compressed into a single commit?

You can change the settings to always squash PRs BTW

zeitlinger commented 4 months ago

Also, could your PR be please compressed into a single commit?

done :smile:

hazendaz commented 4 months ago

True but it's better you do that. Letting remote squash is poor form plus it hurts you later if you properly use rebase. Many old users on github remember when it didn't allow squashing. I find it it mainly means we give up trying to teach proper git usage...;)

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Gregor Zeitlinger @.> Sent: Wednesday, April 24, 2024 12:47:26 PM To: qos-ch/logback @.> Cc: Subscribed @.***> Subject: Re: [qos-ch/logback] make it easier to ingest stack traces into logging backends (Issue #809)

Also, could your PR be please compressed into a single commit?

done 😄

— Reply to this email directly, view it on GitHubhttps://github.com/qos-ch/logback/issues/809#issuecomment-2075405370, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHODI4DUFZS3BRPKXHHDFTY67OZ5AVCNFSM6AAAAABGUJFHQSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZVGQYDKMZXGA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

zeitlinger commented 4 months ago

proper git usage...;)

It's like tabs vs. spaces :wink:

Rebasing from a remote squash is a little bit harder - but it has never bothered me so far. Anyways, just wanted to point out the feature :smile: