scribe icon indicating copy to clipboard operation
scribe copied to clipboard

Standardize JSON output ?

Open fmeriaux opened this issue 2 years ago • 3 comments

There are output differences between the 2 options for logging JSON.

These differences include different property names and output type : messages vs message and list(string) vs string for example.

Sources: https://github.com/outr/scribe/blob/master/jsonFabric/shared/src/main/scala/scribe/json/ScribeFabricJsonSupport.scala#L38 https://github.com/outr/scribe/blob/master/jsonCirce/shared/src/main/scala/scribe/json/ScribeCirceJsonSupport.scala#L23

I propose to standardize around this format (which I think is fairly common):

{
    "timestamp":"1511814391023",
    "logger":"my.demo.logger",
    "message":"Hello world!", # group all messages to one
    "level":"INFO",
    "thread":"thread-name",
    "mdc": {
        "foo":"bar"
      },
    "stack_trace" : " traces ..."
   # etc...
}

What do you think?

fmeriaux avatar Aug 30 '23 08:08 fmeriaux

I'm not opposed to standardizing, I think that's a good plan. However, I think the messages array is useful when there are multiple messages to have a structured way to extract them back out. I'd welcome a PR to provide some standardization.

darkfrog26 avatar Aug 30 '23 13:08 darkfrog26

If I have a bit of time, I'll try to make a PR 🙂

For the message: in my experience, logging tools (which parses the json) expect a single message. I haven't yet come across a usecase where we wanted to put a list of messages for a particular log. Generally, we're going to rely on the stacktrace or the MDC if we want to get something structured out.

But if necessary, I think we can either output 2 properties (1 unique grouped string and 1 for the array), or provide options on which json formatting to choose.

fmeriaux avatar Aug 31 '23 09:08 fmeriaux

That's reasonable. I just try to avoid data-loss as much as possible.

darkfrog26 avatar Aug 31 '23 12:08 darkfrog26