- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.model.util.VariableSubstitutionsHelper
-
- All Implemented Interfaces:
ContextAware,ContextAwarePropertyContainer,PropertyContainer
public class VariableSubstitutionsHelper extends ContextAwareBase implements ContextAwarePropertyContainer
Helper methods to deal with properties.This class acts as a small container for substitution properties and delegates actual variable substitution to
OptionHelper.substVars(java.lang.String, ch.qos.logback.core.spi.PropertyContainer). It also offers a convenience method to mask confidential property values (for example passwords) by returning a blurred placeholder.- Since:
- 1.5.1
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,String>propertiesMap-
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
-
Constructor Summary
Constructors Constructor Description VariableSubstitutionsHelper(Context context)Create a helper backed by an empty property map.VariableSubstitutionsHelper(Context context, Map<String,String> otherMap)Create a helper pre-populated with the contents ofotherMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSubstitutionProperty(String key, String value)Add or overwrite a substitution property.Map<String,String>getCopyOfPropertyMap()Return a shallow copy of the internal property map.StringgetProperty(String key)Retrieve a property value by name.StringsanitizeIfConfidential(String ref, String substituted)Return a blurred placeholder for confidential properties.Stringsubst(String ref)Perform variable substitution on the provided reference string.-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Methods inherited from interface ch.qos.logback.core.spi.ContextAwarePropertyContainer
getConfiguratorSupplier
-
Methods inherited from interface ch.qos.logback.core.spi.PropertyContainer
addSubstitutionProperties
-
-
-
-
Field Detail
-
propertiesMap
protected Map<String,String> propertiesMap
-
-
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 ofotherMap. 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 nullotherMap- 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
nullifrefisnull. On parse errors the original input string is returned and an error is logged.- Specified by:
substin interfaceContextAwarePropertyContainer- Parameters:
ref- the string possibly containing variables to substitute- Returns:
- the string with substitutions applied, or
nullifrefwasnull
-
sanitizeIfConfidential
public String sanitizeIfConfidential(String ref, String substituted)
Return a blurred placeholder for confidential properties.If the property name
refcontains any of the case-insensitive substrings"password","secret"or"confidential"this method returns a fixed blurred string ("******"). Otherwise, the suppliedsubstitutedvalue is returned unchanged.- Parameters:
ref- the property name to inspect; must not benullsubstituted- the substituted value to return when the property is not confidential- Returns:
- a blurred placeholder when the property appears confidential, otherwise
substituted - Throws:
IllegalArgumentException- whenrefisnull
-
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:
addSubstitutionPropertyin interfacePropertyContainer- Parameters:
key- the property name; ignored ifnullvalue- the property value; ignored ifnull
-
getProperty
public String getProperty(String key)
Retrieve a property value by name.- Specified by:
getPropertyin interfacePropertyContainer- Parameters:
key- the property name- Returns:
- the property value or
nullif not present
-
getCopyOfPropertyMap
public Map<String,String> getCopyOfPropertyMap()
Return a shallow copy of the internal property map.The returned map is a copy and modifications to it do not affect the internal state of this helper.
- Specified by:
getCopyOfPropertyMapin interfacePropertyContainer- Returns:
- a copy of the property map
-
-