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?
Asked
Active
Viewed 399 times
0
-
1`Shall i add something to the logback.xml file?`. Hard to say since you didn't show what you already have inside it – Nikolai Shevchenko Sep 22 '21 at 08:45
-
Added picture, also the jsonFactory part was something i just added i will check if this works – Sep 22 '21 at 08:52
-
The jsonFactory did nothing, could it be the filename pattern issue or fieldnames were i should add something – Sep 22 '21 at 08:54
1 Answers
0
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>

Phil Clay
- 4,028
- 17
- 22