If you use SLF4J in conjunction with Logback and Logstash, structured logging is supported with StructuredArguments
. You can find documentation about this on the logstash logback encoder page on Github.
A simple example of how it works. This log line..
log.debug("Retrieved file {}", StructuredArguments.value("filename", upload.getOriginalFilename()))
..yields the following log json output:
{
"filename": "simple.zip",
"@timestamp": "2019-02-12T14:31:31.631+00:00",
"severity": "DEBUG",
"service": "upload",
"thread": "http-nio-9091-exec-1",
"logger": "some.great.ClassName",
"message": "Retrieved file simple.zip"
}