我试过配置 logstash-logback-encoder
版本 6.4
将漂亮的print json打印为
<appender name="consoleAsJSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerData>true</includeCallerData>
<jsonGeneratorDecorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
</encoder>
</appender>
输出为 pretty print
一如预期。然后,我向前一步,将掩蔽配置为
<appender name="consoleAsJSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerData>true</includeCallerData>
<jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>XXXX</defaultMask>
<path>password</path>
</jsonGeneratorDecorator>
</encoder>
</appender>
输出为 marked
也和预期的一样。
不管怎样,当我把这两者结合在一起,它也只做一件事 pretty print
或者 masked
.
<appender name="consoleAsJSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerData>true</includeCallerData>
<jsonGeneratorDecorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
<jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>XXXX</defaultMask>
<path>password</path>
</jsonGeneratorDecorator>
</encoder>
</appender>
它只做 masked
,但是 not pretty print
.
<appender name="consoleAsJSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerData>true</includeCallerData>
<jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>XXXX</defaultMask>
<path>password</path>
</jsonGeneratorDecorator>
<jsonGeneratorDecorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
</encoder>
</appender>
它只做 pretty print
,但是 not masked
.
我该怎么组合 PrettyPrintingJsonGeneratorDecorator
以及 MaskingJsonGeneratorDecorator
一起?你能帮我提个建议吗?
1条答案
按热度按时间uidvcgyl1#
使用CompositeJSongGeneratorDecorator,如下所示: