Skip to content

Mask fields based on log level #509

Answered by philsttr
fdw asked this question in Q&A
Mar 22, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

While logstash-logback-encoder does not have first-class support for this use case, you can accomplish it by creating a custom JsonProvider.

If the sensitive information is contained within well-known MDC properties, then take the following approach:

  1. Prevent the sensitive fields from being logged by the standard MDC json provider via excludeMdcKeyName. See here or here, depending on which encoder you are using.
  2. Create a new custom JsonProvider that inspects the log level of the LoggingEvent, and writes those sensitive MDC fields only if the log level is error
  3. Configure the encoder to use your new custom JsonProvider

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fdw
Comment options

Answer selected by fdw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants