All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.logstash.logback.mask.FieldMasker Maven / Gradle / Ivy

Go to download

Provides logback encoders, layouts, and appenders to log in JSON and other formats supported by Jackson

There is a newer version: 8.0
Show newest version
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.logstash.logback.mask;

import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.node.NullNode;

/**
 * Masks JSON fields within a JSON stream.
 *
 * 

Invoked by {@link MaskingJsonGenerator} after a field name is written * (but before the field's value is known) * to determine if the field's value should be masked.

* *

Comparison with {@link ValueMasker}

* *
    *
  • {@link FieldMasker}s are more efficient than {@link ValueMasker}s, since {@link FieldMasker}s do not inspect values.
  • *
  • {@link FieldMasker}s can mask any type of JSON field (string, number, boolean, array, object), whereas a {@link ValueMasker} can only mask string and number values.
  • *
  • {@link ValueMasker}s can mask element values within an array. {@link FieldMasker}s can only mask field values. *
*/ @FunctionalInterface public interface FieldMasker { /** * If the field at the JSON stream context's current path should be masked, * then returns the masked value to write as the field's value. * The {@link MaskingJsonGenerator} will write the returned masked value * as the field's value (instead of the original field's value). * *

If the JSON stream context's current path should NOT be masked, returns null.

* * @param context the current JSON stream context, which can be used to determine the path within the JSON output. * @return A non-null masked value to write if the current field should be masked. * Otherwise null if the current field should not be masked. * To write a JSON null value as the masked value, return {@link NullNode#instance}. * To write {@value MaskingJsonGenerator#MASK}, the return {@link MaskingJsonGenerator#MASK MaskingJsonGenerator.MASK} */ Object mask(JsonStreamContext context); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy