1

I want to have a unit test in place to verify that the LogstashEncoder is configured correctly and produces JSON formatted logs => logstash-logback-encoder must be registered as a dependency and a logback.xml must be configured.

Trying out the @Captor as described here http://bloodredsun.com/2014/06/03/checking-logback-based-logging-in-unit-tests/ I can only test the content of the message but not its format.

In my concrete case I'm logging the following info: LOG.info("my demo log")

which generates the following log output: {"@timestamp":"2017-01-15T21:43:41.295+01:00","@version":1,"message":"my demo log message","logger_name":"org.sample.project.Application","thread_name":"main","level":"INFO","level_value":20000,"HOSTNAME":"tee"}

But as written above loggingEvent.getFormattedMessage() returns just the message string my demo log.

So what's the trick to get the json formatted message from the LoggingEvent?

Thanks and best regards!

dnltsk
  • 1,037
  • 1
  • 8
  • 9

0 Answers0