tersesystems / terse-logback

Structured Logging, Tracing, and Observability with Logback
https://tersesystems.github.io/terse-logback/
Other
196 stars 14 forks source link

Using multiple censors does not apply all censors #142

Closed dutchmahoney closed 1 year ago

dutchmahoney commented 2 years ago

Describe the bug When using censors, if multiple are applied to net.logstash.logback.encoder.LogstashEncoder using com.tersesystems.logback.censor.CensoringJsonGeneratorDecorator, the last censor-ref "wins" and the others are ignored.

To Reproduce

Expected behavior I expected both censors to be applied to logs, but only the last censor listed in the configuration is applied.

Screenshots (Not a screenshot, but here's the output I'm seeing)

13:51:37,844 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
13:51:37,845 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Users/tim.walter/dev/terse-logback/java/target/classes/logback.xml]
13:51:37,887 |-INFO in ch.qos.logback.core.joran.action.NewRuleAction - About to add new Joran parsing rule [*/censor,com.tersesystems.logback.censor.CensorAction].
13:51:37,887 |-INFO in ch.qos.logback.core.joran.action.NewRuleAction - About to add new Joran parsing rule [*/censor-ref,com.tersesystems.logback.censor.CensorRefAction].
13:51:37,888 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word censor with class [com.tersesystems.logback.censor.CensorConverter]
13:51:37,888 |-INFO in com.tersesystems.logback.censor.CensorAction - About to instantiate censor of type [com.tersesystems.logback.censor.RegexCensor]
13:51:37,889 |-INFO in com.tersesystems.logback.censor.CensorAction - Naming censor as [hunter2]
13:51:37,892 |-INFO in com.tersesystems.logback.censor.CensorAction - About to instantiate censor of type [com.tersesystems.logback.censor.RegexCensor]
13:51:37,892 |-INFO in com.tersesystems.logback.censor.CensorAction - Naming censor as [social-security-number]
13:51:37,893 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
13:51:37,895 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
13:51:37,912 |-INFO in com.tersesystems.logback.censor.CensorRefAction - Attaching censor named [hunter2] to com.tersesystems.logback.censor.CensoringJsonGeneratorDecorator@35b3557eat 27
13:51:37,912 |-INFO in com.tersesystems.logback.censor.CensorRefAction - Attaching censor named [social-security-number] to com.tersesystems.logback.censor.CensoringJsonGeneratorDecorator@35b3557eat 28
13:51:38,020 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
13:51:38,020 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
13:51:38,020 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:51:38,021 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@1188cc16 - Registering current configuration as safe fallback point
{"@timestamp":"2022-09-22T13:51:38.022-04:00","@version":"1","message":"hunter2","logger_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main","thread_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main.main()","level":"INFO","level_value":20000}
{"@timestamp":"2022-09-22T13:51:38.03-04:00","@version":"1","message":"[CENSORED: Social Security Number: 000-11-XXX2]","logger_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main","thread_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main.main()","level":"INFO","level_value":20000}
{"@timestamp":"2022-09-22T13:51:38.041-04:00","@version":"1","message":"SocialSecurityNumber[socialSecurityNumber[CENSORED: Social Security Number: 000-11-XXX2]","logger_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main","thread_name":"io.github.dutchmahoney.terselogbackcensorsexample.Main.main()","level":"INFO","level_value":20000}

Desktop (please complete the following information):

Additional context Nothing more to add but "thanks!"

wsargent commented 1 year ago

The problem here is that I have setCensor and it should be addCensor -- with a little tweaked logic to run through the censors in order. Should be pretty straightforward.