You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2015/12/21 15:21:03 UTC
[2/2] logging-log4j2 git commit: LOG4J2-1080 added method
getDoubleProperty
LOG4J2-1080 added method getDoubleProperty
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/13b0dd87
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/13b0dd87
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/13b0dd87
Branch: refs/heads/master
Commit: 13b0dd8794f52facddb4a27ba7612ddbf7abef4b
Parents: 78c3998
Author: rpopma <rp...@apache.org>
Authored: Sat Dec 19 22:40:05 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Dec 19 22:40:05 2015 +0900
----------------------------------------------------------------------
.../logging/log4j/util/PropertiesUtil.java | 27 ++++++++++++++++++++
1 file changed, 27 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/13b0dd87/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index 77b6497..ff4389c 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -138,6 +138,33 @@ public final class PropertiesUtil {
}
/**
+ * Gets the named property as a double.
+ *
+ * @param name the name of the property to look up
+ * @param defaultValue the default value to use if the property is undefined
+ * @return the parsed double value of the property or {@code defaultValue} if it was undefined or could not be parsed.
+ */
+ public double getDoubleProperty(final String name, final double defaultValue) {
+ String prop = null;
+ try {
+ prop = System.getProperty(name);
+ } catch (final SecurityException ignored) {
+ // Ignore
+ }
+ if (prop == null) {
+ prop = props.getProperty(name);
+ }
+ if (prop != null) {
+ try {
+ return Double.parseDouble(prop);
+ } catch (final Exception ignored) {
+ return defaultValue;
+ }
+ }
+ return defaultValue;
+ }
+
+ /**
* Gets the named property as an integer.
*
* @param name the name of the property to look up