Provides utility methods for managing Properties instances as well as access to the global configuration
system. Properties by default are loaded from the system properties, system environment, and a classpath resource
file named log4j2.component.properties. Additional properties can be loaded by implementing a custom
PropertySource service and specifying it via a ServiceLoader file called
META-INF/services/org.apache.logging.log4j.util.PropertySource with a list of fully qualified class names
implementing that interface.
PropertySource
| Modifier and Type | Class and Description |
|---|---|
| private static class | PropertiesUtil.
Provides support for looking up global configuration properties via environment variables, property files, and system properties, in three variations: Normalized: all log4j-related prefixes removed, remaining property is camelCased with a log4j2 prefix for property files and system properties, or follows a LOG4J_FOO_BAR format for environment variables. |
| private static enum |
| Modifier and Type | Field and Description |
|---|---|
| private static final Lazy | |
| private final PropertiesUtil. | |
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | PropertiesUtil(final Properties
the Properties to use by default props)Constructs a PropertiesUtil using a given Properties object as its source of defined properties. |
| public | PropertiesUtil(final String
the location of properties file to load propertiesFileName)Constructs a PropertiesUtil for a given properties file name on the classpath. |
| private | |
| pack-priv | PropertiesUtil(final PropertySource
a property source source)Constructs a PropertiesUtil for a give property source as source of additional properties. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addPropertySource(final PropertySource
the PropertySource to add. propertySource)Allows a PropertySource to be added after PropertiesUtil has been created. |
| public static Properties | Returns: The subset of properties.The Properties to evaluate. properties, final String The prefix to extract. prefix)Extracts properties that start with or are equals to the specific prefix and returns them in a new Properties object with the prefix removed. |
| public boolean | Returns: the boolean value of the property orfalse if undefined.the name of the property to look up name)Gets the named property as a boolean value. |
| public boolean | Returns: the boolean value of the property ordefaultValue if undefined.the name of the property to look up name, final boolean the default value to use if the property is undefined defaultValue)Gets the named property as a boolean value. |
| public boolean | Returns: the boolean value of the property ordefaultValue if undefined.the name of the property to look up name, final boolean the default value to use if the property is undefined defaultValueIfAbsent, final boolean the default value to use if the property is defined but not assigned defaultValueIfPresent)Gets the named property as a boolean value. |
| public Boolean | Returns: The value or null if it is not found.The array of prefixes. prefixes, final String The key to locate. key, final Supplier<Boolean> The method to call to derive the default value. If the value is null, null will be returned
if no property is found. supplier)
References Deprecated
Supplier is deprecated or references (maybe indirectly) at least one deprecated element.
Retrieves a property that may be prefixed by more than one string. |
| public Charset | Returns: the Charset value of the property orCharset#defaultCharset() if undefined.the name of the property to look up name)Gets the named property as a Charset value. |
| public Charset | Returns: the Charset value of the property ordefaultValue if undefined.the name of the property to look up name, final Charset the default value to use if the property is undefined defaultValue)Gets the named property as a Charset value. |
| pack-priv static ResourceBundle | |
| public double | Returns: the parsed double value of the property ordefaultValue if it was undefined or could not be parsed.the name of the property to look up name, final double the default value to use if the property is undefined defaultValue)Gets the named property as a double. |
| public Duration | Returns: The value of the String as a Duration or the default value, which may be null.The property name. name, final Duration The default value. defaultValue)Retrieves a Duration where the String is of the format nnn[unit] where nnn represents an integer value and unit represents a time unit. |
| public Duration | Returns: The value or null if it is not found.The array of prefixes. prefixes, final String The key to locate. key, final Supplier<Duration> The method to call to derive the default value. If the value is null, null will be returned
if no property is found. supplier)
References Deprecated
Supplier is deprecated or references (maybe indirectly) at least one deprecated element.
Retrieves a property that may be prefixed by more than one string. |
| public int | Returns: the parsed integer value of the property ordefaultValue if it was undefined or could not be
parsed.the name of the property to look up name, final int the default value to use if the property is undefined defaultValue)Gets the named property as an integer. |
| public Integer | Returns: The value or null if it is not found.The array of prefixes. prefixes, final String The key to locate. key, final Supplier<Integer> The method to call to derive the default value. If the value is null, null will be returned
if no property is found. supplier)
References Deprecated
Supplier is deprecated or references (maybe indirectly) at least one deprecated element.
Retrieves a property that may be prefixed by more than one string. |
| public long | Returns: the parsed long value of the property ordefaultValue if it was undefined or could not be parsed.the name of the property to look up name, final long the default value to use if the property is undefined defaultValue)Gets the named property as a long. |
| public Long | Returns: The value or null if it is not found.The array of prefixes. prefixes, final String The key to locate. key, final Supplier<Long> The method to call to derive the default value. If the value is null, null will be returned
if no property is found. supplier)
References Deprecated
Supplier is deprecated or references (maybe indirectly) at least one deprecated element.
Retrieves a property that may be prefixed by more than one string. |
| public static PropertiesUtil | Returns: the main Log4j PropertiesUtil instance.Returns the PropertiesUtil used by Log4j. |
| public String | Returns: The value or null if it is not found.The array of prefixes. prefixes, final String The key to locate. key, final Supplier<String> The method to call to derive the default value. If the value is null, null will be returned
if no property is found. supplier)
References Deprecated
Supplier is deprecated or references (maybe indirectly) at least one deprecated element.
Retrieves a property that may be prefixed by more than one string. |
| public String | Returns: the String value of the property ornull if undefined.the name of the property to look up name)Gets the named property as a String. |
| public String | Returns: the String value of the property ordefaultValue if undefined.the name of the property to look up name, final String the default value to use if the property is undefined defaultValue)Gets the named property as a String. |
| public static Properties | Returns: The system properties.Return the system properties or an empty Properties object if an error occurs. |
| public boolean | Returns: true if the specified property is defined, regardless of its valuethe name of the property to verify name)Returns |
| public boolean | Returns: true if system properties tell us we are running on Windows.Returns true if system properties tell us we are running on Windows. |
| pack-priv static Properties | Returns: a new Properties objecta property input stream. in, final Object a source object describing the source, like a resource string or a URL. source)Loads and closes the given property input stream. |
| public static Map | Returns: the partitioned properties where each key is the common prefix (minus the period) and the values are new property maps without the prefix and period in the keyproperties to partition properties)Partitions a properties map based on common key prefixes up to the first period. |
| public static Map | Returns: the partitioned properties where each key is the common prefix (minus the period) and the values are new property maps without the prefix and period in the keyproperties to partition properties, final boolean when true if a key exists with no '.' the key will be included. includeBaseKey)Partitions a properties map based on common key prefixes up to the first period. |
| public void |
| COMPONENT_PROPERTIES | back to summary |
|---|---|
| private static final Lazy<PropertiesUtil> COMPONENT_PROPERTIES | |
| environment | back to summary |
|---|---|
| private final PropertiesUtil. | |
| LOG4J_PROPERTIES_FILE_NAME | back to summary |
|---|---|
| private static final String LOG4J_PROPERTIES_FILE_NAME | |
| LOG4J_SYSTEM_PROPERTIES_FILE_NAME | back to summary |
|---|---|
| private static final String LOG4J_SYSTEM_PROPERTIES_FILE_NAME | |
| PropertiesUtil | back to summary |
|---|---|
| public PropertiesUtil(final Properties props) Constructs a PropertiesUtil using a given Properties object as its source of defined properties.
| |
| PropertiesUtil | back to summary |
|---|---|
| public PropertiesUtil(final String propertiesFileName) Constructs a PropertiesUtil for a given properties file name on the classpath. The properties specified in this file are used by default. If a property is not defined in this file, then the equivalent system property is used.
| |
| PropertiesUtil | back to summary |
|---|---|
| private PropertiesUtil(final String propertiesFileName, final boolean useTccl) | |
| PropertiesUtil | back to summary |
|---|---|
| pack-priv PropertiesUtil(final PropertySource source) Constructs a PropertiesUtil for a give property source as source of additional properties.
| |
| addPropertySource | back to summary |
|---|---|
| public void addPropertySource(final PropertySource propertySource) Allows a PropertySource to be added after PropertiesUtil has been created.
| |
| extractSubset | back to summary |
|---|---|
| public static Properties extractSubset(final Properties properties, final String prefix) Extracts properties that start with or are equals to the specific prefix and returns them in a new Properties object with the prefix removed.
| |
| getBooleanProperty | back to summary |
|---|---|
| public boolean getBooleanProperty(final String name) Gets the named property as a boolean value. If the property matches the string
| |
| getBooleanProperty | back to summary |
|---|---|
| public boolean getBooleanProperty(final String name, final boolean defaultValue) Gets the named property as a boolean value.
| |
| getBooleanProperty | back to summary |
|---|---|
| public boolean getBooleanProperty(final String name, final boolean defaultValueIfAbsent, final boolean defaultValueIfPresent) Gets the named property as a boolean value.
| |
| getBooleanProperty | back to summary |
|---|---|
| public Boolean getBooleanProperty(final String[] prefixes, final String key, final Supplier<Boolean> supplier)
References Deprecated
See corresponding docs for further information. Retrieves a property that may be prefixed by more than one string.
| |
| getCharsetProperty | back to summary |
|---|---|
| public Charset getCharsetProperty(final String name) Gets the named property as a Charset value.
| |
| getCharsetProperty | back to summary |
|---|---|
| public Charset getCharsetProperty(final String name, final Charset defaultValue) Gets the named property as a Charset value. If we cannot find the named Charset, see if it is mapped in
file | |
| getCharsetsResourceBundle | back to summary |
|---|---|
| pack-priv static ResourceBundle getCharsetsResourceBundle() | |
| getDoubleProperty | back to summary |
|---|---|
| public double getDoubleProperty(final String name, final double defaultValue) Gets the named property as a double.
| |
| getDurationProperty | back to summary |
|---|---|
| public Duration getDurationProperty(final String name, final Duration defaultValue) Retrieves a Duration where the String is of the format nnn[unit] where nnn represents an integer value and unit represents a time unit. | |
| getDurationProperty | back to summary |
|---|---|
| public Duration getDurationProperty(final String[] prefixes, final String key, final Supplier<Duration> supplier)
References Deprecated
See corresponding docs for further information. Retrieves a property that may be prefixed by more than one string.
| |
| getIntegerProperty | back to summary |
|---|---|
| public int getIntegerProperty(final String name, final int defaultValue) Gets the named property as an integer.
| |
| getIntegerProperty | back to summary |
|---|---|
| public Integer getIntegerProperty(final String[] prefixes, final String key, final Supplier<Integer> supplier)
References Deprecated
See corresponding docs for further information. Retrieves a property that may be prefixed by more than one string.
| |
| getLongProperty | back to summary |
|---|---|
| public long getLongProperty(final String name, final long defaultValue) Gets the named property as a long.
| |
| getLongProperty | back to summary |
|---|---|
| public Long getLongProperty(final String[] prefixes, final String key, final Supplier<Long> supplier)
References Deprecated
See corresponding docs for further information. Retrieves a property that may be prefixed by more than one string.
| |
| getProperties | back to summary |
|---|---|
| public static PropertiesUtil getProperties() Returns the PropertiesUtil used by Log4j.
| |
| getStringProperty | back to summary |
|---|---|
| public String getStringProperty(final String[] prefixes, final String key, final Supplier<String> supplier)
References Deprecated
See corresponding docs for further information. Retrieves a property that may be prefixed by more than one string.
| |
| getStringProperty | back to summary |
|---|---|
| public String getStringProperty(final String name) Gets the named property as a String. | |
| getStringProperty | back to summary |
|---|---|
| public String getStringProperty(final String name, final String defaultValue) Gets the named property as a String. | |
| getSystemProperties | back to summary |
|---|---|
| public static Properties getSystemProperties() Return the system properties or an empty Properties object if an error occurs.
| |
| hasProperty | back to summary |
|---|---|
| public boolean hasProperty(final String name) Returns
| |
| isOsWindows | back to summary |
|---|---|
| public boolean isOsWindows() Returns true if system properties tell us we are running on Windows.
| |
| loadClose | back to summary |
|---|---|
| pack-priv static Properties loadClose(final InputStream in, final Object source) Loads and closes the given property input stream. If an error occurs, log to the status logger.
| |
| partitionOnCommonPrefixes | back to summary |
|---|---|
| public static Map Partitions a properties map based on common key prefixes up to the first period.
| |
| partitionOnCommonPrefixes | back to summary |
|---|---|
| public static Map Partitions a properties map based on common key prefixes up to the first period.
| |
| reload | back to summary |
|---|---|
| public void reload() Reloads all properties. This is primarily useful for unit tests.
| |
Normalized: all log4j-related prefixes removed, remaining property is camelCased with a log4j2 prefix for property files and system properties, or follows a LOG4J_FOO_BAR format for environment variables.
Legacy: the original property name as defined in the source pre-2.10.0.
Tokenized: loose matching based on word boundaries.
| Modifier and Type | Field and Description |
|---|---|
| private final Map | literal
Maps a key to its value or the value of its normalization in the lowest priority source that contains it. |
| private final Set | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | addPropertySource(final PropertySource
The PropertySource to add. propertySource)Allow a PropertySource to be added. |
| private boolean | |
| private String | |
| private synchronized void |
| literal | back to summary |
|---|---|
| private final Map<String, String> literal Maps a key to its value or the value of its normalization in the lowest priority source that contains it. | |
| sources | back to summary |
|---|---|
| private final Set<PropertySource> sources | |
| tokenized | back to summary |
|---|---|
| private final Map<List<CharSequence>, String> tokenized | |
| Environment | back to summary |
|---|---|
| private Environment(final PropertySource propertySource) | |
| addPropertySource | back to summary |
|---|---|
| public void addPropertySource(final PropertySource propertySource) Allow a PropertySource to be added.
| |
| containsKey | back to summary |
|---|---|
| private boolean containsKey(final String key) | |
| get | back to summary |
|---|---|
| private String get(final String key) | |
| reload | back to summary |
|---|---|
| private synchronized void reload() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final PropertiesUtil. | |
| private final String[] | |
| public static final PropertiesUtil. | |
| public static final PropertiesUtil. | |
| public static final PropertiesUtil. | |
| public static final PropertiesUtil. | |
| public static final PropertiesUtil. | |
| public static final PropertiesUtil. | |
| private final ChronoUnit |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static Duration | |
| public static PropertiesUtil. | |
| public static PropertiesUtil. |
| DAYS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| descriptions | back to summary |
|---|---|
private final String[] descriptions
| |
| HOURS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| MICROS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| MILLIS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| MINUTES | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| NANOS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| SECONDS | back to summary |
|---|---|
| public static final PropertiesUtil. | |
| timeUnit | back to summary |
|---|---|
| private final ChronoUnit timeUnit | |
| TimeUnit | back to summary |
|---|---|
| private TimeUnit(final String descriptions, final ChronoUnit timeUnit) | |
| getDuration | back to summary |
|---|---|
| pack-priv static Duration getDuration(final String time) | |
| valueOf | back to summary |
|---|---|
| public static PropertiesUtil. | |
| values | back to summary |
|---|---|
| public static PropertiesUtil. | |