In a JVM project, we're using logstash to log messages with additional JSON data on production servers.
The problem is that the JSON is hard to read in console. So, I tried to changed to the local (dev) configuration to use PatternLayoutEncoder and have nice, clean logs locally.
I found this issue: https://github.com/logstash/logstash-logback-encoder/issues/136
The conclusion was that with logstash logback encoder 5.0, we can now unify the key/value pairs with Structured Parameters.
I did that, and it works great, but they problem I have is that now on logstash the pairs are repeated both in the message and the JSON.
- For the console I'm using
ch.qos.logback.classic.encoder.PatternLayoutEncoder
- For JSON I'm using
net.logstash.logback.encoder.LogstashEncoder
Either I do this:
LOGGER.info("Some message", kv("user_id", 1));
The logstash json is this:
{ message: "Some message", user_id: 1 }
But the console log is doesn't have the parameter:
2018-04-10 08:38:38,042 INFO - Some message
Or I do this:
LOGGER.info("Some message {}", kv("user_id", 1));
The logstash json has duplicated info (not good):
{ message: "Some message user_id=1", user_id: 1 }
And the console log is what I want:
2018-04-10 08:38:38,042 INFO - Some message user_id=1
So my question is:
How can I configure my logs so I get the additional infos in the console, in a clean way, but not have them duplicated in the JSON?