Class VariableSubstitutionsHelper
- All Implemented Interfaces:
ContextAware,ContextAwarePropertyContainer,PropertyContainer
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
FieldsFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
ConstructorsConstructorDescriptionVariableSubstitutionsHelper(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
Modifier and TypeMethodDescriptionvoidaddSubstitutionProperty(String key, String value) Add or overwrite a substitution property.Return a shallow copy of the internal property map.getProperty(String key) Retrieve a property value by name.sanitizeIfConfidential(String ref, String substituted) Return a blurred placeholder for confidential properties.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, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContextMethods inherited from interface ch.qos.logback.core.spi.ContextAwarePropertyContainer
getConfiguratorSupplierMethods inherited from interface ch.qos.logback.core.spi.PropertyContainer
addSubstitutionProperties
-
Field Details
-
propertiesMap
-
-
Constructor Details
-
VariableSubstitutionsHelper
Create a helper backed by an empty property map.- Parameters:
context- the logback context to associate with this helper; may be null
-
VariableSubstitutionsHelper
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 Details
-
subst
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
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
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
Retrieve a property value by name.- Specified by:
getPropertyin interfacePropertyContainer- Parameters:
key- the property name- Returns:
- the property value or
nullif not present
-
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
-