0

我必须掩盖日志中的敏感信息,但只是部分掩盖。例如,我需要将电子邮件 'kate@example.com' 替换为 'k***@e***' 是否可以使用 logstash-logback-encoder 来做到这一点?

目前我使用这个 logback.xml:

<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">

        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <fieldNames>
                <timestamp>timestamp</timestamp>
            </fieldNames>
        </encoder>
        <!-- see https://github.com/logfellow/logstash-logback-encoder#identifying-field-values-to-mask-by-value -->
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
                <value>(\w+@\w+\.\w+)</value>
                <path>message/*</path>
            </jsonGeneratorDecorator>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

有了它,我得到:

{"@timestamp":"2021-12-21T17:17:15.072+02:00","@version":"1","message":"email=********)]", "logger_name":"org.ba.SpringLogginProcessingExampleApplication","thread_name":"main","level":"INFO","level_value":20000}

我更喜欢 LogEvent(email=k****@e*** vs email=****

4

1 回答 1

0

是的。掩码可以引用值正则表达式中的捕获组。

像这样的东西:

    <valueMask>
        <value>(\w)\w*@(\w)\w*\.(\w)\w*</value>
        <mask>$1****@$2****.$3****</mask>
    </valueMask>
于 2021-12-21T17:17:34.053 回答