Logstash encoder doesnt produce correct json format

671 views Asked by At

logback jsonfile

When i produce json logging with loggerfactory it forgets to add commas after each row, any tips? Shall i add something to the logback.xml file?

1

There are 1 answers

0
Phil Clay On

The output of the LogstashEncoder is intended to be sent to something that expects line-delimited JSON objects, such as logstash's json_lines codec.

Note that adding a comma between JSON objects does not make it valid JSON, since there is no leading [ or trailing ] for an array.

Having said that, you can add comma after each object by configuring a suffix or line separator

For example, to add a suffix:

    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
      ...
      <suffix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
        <layout class="ch.qos.logback.classic.PatternLayout">
          <pattern>,</pattern>
        </layout>
      </prefix>    
    </encoder>
  </appender>