Open vcolin7 opened 5 months ago
Determine how we want to JSON structured logging to look like
There are two options:
Don't change anything for SLF4J 2.0. As a result, SLF4J 2.0 providers would get string message (which happens to be structured json) and won't see individual key-value-pairs
Leverage the structure and use SLF4J 2.0 addKeyValue
methods to provide the context to the SDLF4J
The middle ground:
E.g. we want to record the following log: connectionId=foo, error.type=canceled, message="Connection attempt failed"
With SLF4J 1.7 we record message as {"connectionId":"foo", "error.type":"canceled", "message":"Connection attempt failed"}
With SLF4J 2.0 we record structured things and a formatted message like
slf4JLogger.atInfo()
.addKeyValue("connectionId", "foo")
.addKeyValue("error.type", "canceled")
.addKeyValue("message", "Connection attempt failed")
.log("{\"connectionId\":\"foo\", \"error.type\":\"canceled\", \"message\":\"Connection attempt failed\"}")
This would be a default behavior resulting in:
It'd result in duplication and we can consider letting users to configure it.
My proposal is to do 1.5 eventually, but stick with option 1 for now until we have any feedback/scenario for option 1.5.
By doing option 1, we effectively do
slf4JLogger.atInfo()
.log("{\"connectionId\":\"foo\", \"error.type\":\"canceled\", \"message\":\"Connection attempt failed\"}")
and
.addKeyValue("connectionId", "foo")
.addKeyValue("error.type", "canceled")
.addKeyValue("message", "Connection attempt failed")
is purely incremental change.