Class VariableSubstitutionsHelper

    • Constructor Detail

      • VariableSubstitutionsHelper

        public VariableSubstitutionsHelper​(Context context)
        Create a helper backed by an empty property map.
        Parameters:
        context - the logback context to associate with this helper; may be null
      • VariableSubstitutionsHelper

        public VariableSubstitutionsHelper​(Context context,
                                           Map<String,​String> otherMap)
        Create a helper pre-populated with the contents of otherMap. The provided map is copied and further modifications do not affect the original map.
        Parameters:
        context - the logback context to associate with this helper; may be null
        otherMap - initial properties to copy; if null an empty map is created
    • Method Detail

      • subst

        public String subst​(String ref)
        Perform variable substitution on the provided reference string.

        Returns null if ref is null. On parse errors the original input string is returned and an error is logged.

        Specified by:
        subst in interface ContextAwarePropertyContainer
        Parameters:
        ref - the string possibly containing variables to substitute
        Returns:
        the string with substitutions applied, or null if ref was null
      • sanitizeIfConfidential

        public String sanitizeIfConfidential​(String ref,
                                             String substituted)
        Return a blurred placeholder for confidential properties.

        If the property name ref contains any of the case-insensitive substrings "password", "secret" or "confidential" this method returns a fixed blurred string ("******"). Otherwise, the supplied substituted value is returned unchanged.

        Parameters:
        ref - the property name to inspect; must not be null
        substituted - the substituted value to return when the property is not confidential
        Returns:
        a blurred placeholder when the property appears confidential, otherwise substituted
        Throws:
        IllegalArgumentException - when ref is null
      • addSubstitutionProperty

        public void addSubstitutionProperty​(String key,
                                            String value)
        Add or overwrite a substitution property.

        Null keys or values are ignored. Values are trimmed before storing to avoid surprises caused by leading or trailing whitespace.

        Specified by:
        addSubstitutionProperty in interface PropertyContainer
        Parameters:
        key - the property name; ignored if null
        value - the property value; ignored if null