At the moment, this code
LOG4J.info(new MapMessage<>().with("foo", true).with("bar", 1.0));
leads to this output:
{"@timestamp":"2024-08-27T14:05:28.609449Z","log.level":"INFO","process.pid":13608,"process.thread.name":"main","service.name":"structured-logging-playground","log.logger":"com.example.structuredloggingplayground.CLR","message":"bar=\"1.0\" foo=\"true\"","ecs.version":"8.11"}
Instead, it should add "foo" and "bar" as separate keys and also preserve the datatypes.
Comment From: mhalbritter
We should also see if there are more subtypes of Message which are suitable for structured logging.
Comment From: philwebb
I think we have couple of options here, we could call MapMessage.getData() and use our JsonWriter to write the result, or we could use MultiFormatStringBuilderFormattable and let it write the JSON.
I took a stab at the second option in https://github.com/philwebb/spring-boot/tree/gh-42034 if you want to take a look @mhalbritter.
Comment From: mhalbritter
Thanks Phil, that looks good!