Better structured JSON logging

Hi :wave:

We’ve automated our regular load tests, and now we’re looking into getting better observability for them. We’re using Datadog, and we’re already successfully exporting metrics to it.

We’d also like to export the logs to Datadog.

We’ve discovered --log-format json (the documented shorthand -f doesn’t work, btw.) which is already good to have, but for us it’s not quite useful yet, because we can’t seem to have custom fields in the JSON output.

I could imagine something like this to add custom fields:

console.log("message", {"foo": 42})

But instead of this:

{
  "level": "info",
  "msg": "message",
  "foo": 42",
  "source": "console",
  "time": "2024-02-28T10:12:03+01:00"
}

It results in this:

{
  "level": "info",
  "msg": "message {\"foo\":42}",
  "source": "console",
  "time": "2024-02-28T10:12:03+01:00"
}

Would be nice if this worked :pray:

Hi @maxeludwig,

This is interesting idea, but unfortunately is not intended at all.

Looking at the console specification this is definitely not what the intention was as well.

For a short while it used to something like that - which was indentified as a bug and not compatible with browsers or node.

Looking around structured logging(the thing want it seems) just isn’t supported with the basic console :person_shrugging: .

Nodejs has a bunch of libraries around it, but nothing stdlib or as part of console.

I would argue that this will be a breaking change to console and make it strange for users who do not expect this but instead expect the actually defined behaviour of concatting the args and that becoming the message.

I also think this is valuable - so I propose you open a feature request and maybe try to propose alternative APIs or a way to make it into console that won’t break current or future compatability with the standard.