Pretty printing: leading space because of root value separator #906
Unanswered
bresalio-nagy-dynata
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Unfortunately not in 7.2. In 7.3, I have changed the default root separator of the pretty printer to be an empty string, and added the ability to configure it differently. See #926 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm configuring LogstashEncoder from logback-spring.xml, and I'd like to use pretty printing.
I've found in the doc that it can be achieved with this config:
<jsonGeneratorDecorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
However, this decorator inserts a leading space in front of the opening { of the output JSON, therefore the first line, which only contains a { character, will be indented into the same level as the keys in the following lines:
According to what I've seen of the background in the code, this is because the root value separator is " " in DefaultPrettyPrinter.
I've created a custom CustomPrettyPrintingJsonGeneratorDecorator, in which I create and set a new PrettyPrinter, whose root value separator will be an empty string, and this one works as expected, this custom decorator doesn't print the leading space. But if possible, we'd like to avoid creating extra classes for the sake of log config, and we would like to keep log config in logback-spring.xml.
Is there any way to configure the root value separator to be used by the JsonGenerator's PrettyPrinter, without subclassing anything, barely from the logback XML config file? ^_^
Beta Was this translation helpful? Give feedback.
All reactions