deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-1126 add a config switch to log values when they got changed
Date Tue, 12 Apr 2016 07:05:21 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 963190661 -> 373771829


DELTASPIKE-1126 add a config switch to log values when they got changed


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/37377182
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/37377182
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/37377182

Branch: refs/heads/master
Commit: 37377182945933bd4892595d1362d795a0fc488a
Parents: 9631906
Author: Mark Struberg <struberg@apache.org>
Authored: Tue Apr 12 08:56:19 2016 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Tue Apr 12 08:57:54 2016 +0200

----------------------------------------------------------------------
 .../core/api/config/ConfigResolver.java         | 23 ++++++++++++++++++++
 .../test/api/config/ConfigResolverTest.java     |  3 ++-
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/37377182/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index ec5bf1a..f2ad42c 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -650,6 +650,13 @@ public final class ConfigResolver
         TypedResolver<T> evaluateVariables(boolean evaluateVariables);
 
         /**
+         * Whether to log picking up any value changes as INFO.
+         *
+         * @return This builder
+         */
+        TypedResolver<T> logChanges(boolean logChanges);
+
+        /**
          * Returns the converted resolved filtered value.
          * @return the resolved value
          */
@@ -749,6 +756,7 @@ public final class ConfigResolver
         private Converter<?> converter;
 
         private boolean evaluateVariables = false;
+        private boolean logChanges = false;
 
         private long cacheTimeMs = -1;
         private volatile long reloadAfter = -1;
@@ -852,6 +860,13 @@ public final class ConfigResolver
         }
 
         @Override
+        public TypedResolver<T> logChanges(boolean logChanges)
+        {
+            this.logChanges = logChanges;
+            return this;
+        }
+
+        @Override
         public T getValue()
         {
             if (cacheTimeMs > 0)
@@ -868,10 +883,18 @@ public final class ConfigResolver
             T value = convert(valueStr);
 
             value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
+
+            if (logChanges && (value != null && lastValue == null || !value.equals(lastValue))
)
+            {
+                LOG.log(Level.INFO, "New value {0} for key {1}.",
+                    new Object[]{filterConfigValueForLog(keyOriginal, valueStr), keyOriginal});
+            }
+
             if (cacheTimeMs > 0)
             {
                 lastValue = value;
             }
+
             return value;
         }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/37377182/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
index bfac665..50f996a 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -155,7 +155,8 @@ public class ConfigResolverTest
         String url = ConfigResolver.getPropertyValue("deltaspike.test.recursive.variable1",
"", true);
         Assert.assertEquals("pre-crazy-post/ohgosh/crazy", url);
 
-        ConfigResolver.TypedResolver<String> tr = ConfigResolver.resolve("deltaspike.test.recursive.variable1").evaluateVariables(true);
+        ConfigResolver.TypedResolver<String> tr = ConfigResolver.resolve("deltaspike.test.recursive.variable1")
+            .evaluateVariables(true).logChanges(true);
         Assert.assertEquals("pre-crazy-post/ohgosh/crazy", tr.getValue());
     }
 


Mime
View raw message