Class SystemPropertySupplier<T>
java.lang.Object
org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier<T>
- All Implemented Interfaces:
Supplier<T>
Utility class for consistent handling of system properties.
It provides for:
- TRACE level logging of getting the system property
- ERROR level logging when value does not parse or is invalid (where
validity can be checked by a
Predicate) - (default) INFO level logging when value differs from default (log level and message format can be overridden)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <U> SystemPropertySupplier<U>Create it for a given property name and default value.formatSetMessage(@NotNull BiFunction<String, T, String> setMessageFormatter) Specify a formatter for the "success" log message to be used when the returned property value differs from the default.get()Obtains the value of a system property, optionally generating diagnostics.Used to hide property value in log messages (for instance, for passwords)Specify theLoggerto log to (defaults to this classes logger otherwise).logSuccessAs(String successLogLevel) SpecifyLevelto use for "success" message (defaults to "INFO")protected SystemPropertySupplier<T>usingSystemPropertyReader(@NotNull Function<String, String> sysPropReader) For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String).validateWith(@NotNull Predicate<T> validator) Specify a validation expression.
-
Method Details
-
create
public static <U> SystemPropertySupplier<U> create(@NotNull @NotNull String propName, @NotNull U defaultValue) throws IllegalArgumentException Create it for a given property name and default value.- Throws:
IllegalArgumentException
-
loggingTo
Specify theLoggerto log to (defaults to this classes logger otherwise). -
validateWith
Specify a validation expression. -
formatSetMessage
public SystemPropertySupplier<T> formatSetMessage(@NotNull @NotNull BiFunction<String, T, String> setMessageFormatter) Specify a formatter for the "success" log message to be used when the returned property value differs from the default. -
logSuccessAs
SpecifyLevelto use for "success" message (defaults to "INFO") -
hideValue
Used to hide property value in log messages (for instance, for passwords)Note: will have no effect when custom message formatter is used (see
setMessageFormatter). -
usingSystemPropertyReader
protected SystemPropertySupplier<T> usingSystemPropertyReader(@NotNull @NotNull Function<String, String> sysPropReader) For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String). -
get
Obtains the value of a system property, optionally generating diagnostics.
-