Reputation: 2161
At some places we are logging JSON strings. For better readability we want to pretty print them. Therefore we are using:
v_JsonString = v_ObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v_Json);
But after passing the result to the logger the string is only single line, the line breaks etc are gone. The used logging pattern is:
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{35} - %msg%n</pattern>
We also tried to do it manually by setting some placeholders and replace them in the pattern:
%replace(%msg){'PLACEHOLDER', '\\n'}
Without any success, every log entry is converted to single line. What is the correct way to preserve formatted string information?
EDIT The problem is not the logger, Jackson does not pretty print strings without serialization, see https://stackoverflow.com/a/39119883/1924298
Upvotes: 1
Views: 3146
Reputation: 10562
Object json = mapper.readValue(input, Object.class);
String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
Upvotes: 3
Reputation: 2161
The problem is solved. The problem was not the logger / settings. The real cause is described here: https://stackoverflow.com/a/20871355/1924298
EDIT
The problem is not solved as getting serialization error when trying with type "Object". I will edit the original question.
Upvotes: 1