英文:
How can I combine PrettyPrintingJsonGeneratorDecorator and MaskingJsonGeneratorDecorator together?
问题
我已尝试配置logstash-logback-encoder
版本6.4
以打印漂亮的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>
输出符合预期,为漂亮的打印
。然后,我尝试配置掩码,如下所示:
<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>
输出符合预期,为标记的
格式。然而,当我将这两者结合在一起时,它只能执行其中一个操作,要么是漂亮的打印
要么是标记的
。
<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>
这只会执行标记的
操作,而不会进行漂亮的打印
。同样地,如果将这两个装饰器的顺序颠倒,将只执行漂亮的打印
而不进行标记的
操作。
您如何才能将PrettyPrintingJsonGeneratorDecorator
和MaskingJsonGeneratorDecorator
结合在一起?能否请您提供建议?
英文:
I've tried to config the logstash-logback-encoder
version 6.4
to print the pretty print JSON as
<!-- language: xml -->
<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>
The output is pretty print
as expected. Then I step forward to config with masking as
<!-- language: xml -->
<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>
The output is marked
as expected, too.
Anyhow when I combine these two together, it only does one thing, either pretty print
or masked
.
<!-- language: xml -->
<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>
It only does the masked
, but not pretty print
.
<!-- language: xml -->
<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>
It only does the pretty print
, but not masked
.
How can I combine PrettyPrintingJsonGeneratorDecorator
and MaskingJsonGeneratorDecorator
together? Could you please help to advise?
答案1
得分: 5
使用 CompositeJsonGeneratorDecorator,如下所示:
<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.CompositeJsonGeneratorDecorator">
<decorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
<decorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>XXXX</defaultMask>
<path>password</path>
</decorator>
</jsonGeneratorDecorator>
</encoder>
</appender>
英文:
Use a CompositeJsonGeneratorDecorator, like this:
<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.CompositeJsonGeneratorDecorator">
<decorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
<decorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>XXXX</defaultMask>
<path>password</path>
</decorator>
</jsonGeneratorDecorator>
</encoder>
</appender>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论