qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.97k stars 1.28k forks source link

Mask or remove specific words from log line #828

Closed router19 closed 2 weeks ago

router19 commented 1 month ago

Hi I have a requirement wherein I would want to match a specific regex and dont allow words matching such regex to be logged.

I explored logback matcher but it removed the complete formated message. I need only a specific word matching regex in the formatted message to be removed or replaced with some characters say *

Example

Formatted message : I love logback library as it is best.

Ouput I want if logback matches the regex : I love library as it is best Or I love *** library as it is best

ceki commented 1 month ago

Hi Vinit,

Logback comes with the replace conversion word which corresponds to your requirements.

router19 commented 1 month ago

Thank you for your response. Will that impact performance of the application as each log line will be matched against the regex.

On Thu, 4 Jul, 2024, 17:47 Ceki Gülcü, @.***> wrote:

Hi Vinit,

Logback comes with the replace pattern https://logback.qos.ch/manual/layouts.html#replace which corresponds to your requirements.

— Reply to this email directly, view it on GitHub https://github.com/qos-ch/logback/issues/828#issuecomment-2208833503, or unsubscribe https://github.com/notifications/unsubscribe-auth/APH2RA4LP5SWD6OOFHT6RCTZKU4OXAVCNFSM6AAAAABKKCAZPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBYHAZTGNJQGM . You are receiving this because you authored the thread.Message ID: @.***>

ceki commented 1 month ago

Yes, there will be some a performance impact. However, I have not tested the extent of the impact.

Added LOGBACK-1770 for tracking this issue.

ceki commented 2 weeks ago

Fixed in commit e7d945906d3b156 which introduces %maskedKvp converter.