You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:39:54 UTC

[sling-org-apache-sling-hc-support] 07/31: SLING-3020 - Result is now immutable

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.hc.support-1.0.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-support.git

commit bcce508d6e6d07f6659c0ec7b01fd84b89115b6d
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Aug 15 14:19:46 2013 +0000

    SLING-3020 - Result is now immutable
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/healthcheck/healthchecks@1514287 13f79535-47bb-0310-9956-ffa450edef68
---
 .../hc/healthchecks/impl/CompositeHealthCheck.java | 34 +++++++--------
 .../impl/DefaultLoginsHealthCheck.java             | 20 ++++-----
 .../healthchecks/impl/JmxAttributeHealthCheck.java | 21 ++++------
 .../hc/healthchecks/impl/JmxScriptBinding.java     | 19 ++++-----
 .../hc/healthchecks/impl/OsgiScriptBinding.java    | 20 ++++-----
 .../healthchecks/impl/ScriptableHealthCheck.java   | 34 ++++++---------
 .../impl/SlingRequestStatusHealthCheck.java        | 25 +++++------
 .../hc/healthchecks/util/FormattingResultLog.java  | 49 ++++++++++++++++++++++
 .../hc/healthchecks/JmxScriptBindingTest.java      | 10 ++---
 .../hc/healthchecks/OsgiScriptBindingTest.java     | 10 ++---
 10 files changed, 126 insertions(+), 116 deletions(-)

diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
index 59edcf6..e459b0d 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/CompositeHealthCheck.java
@@ -30,7 +30,8 @@ import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.api.ResultLog;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.apache.sling.hc.util.HealthCheckFilter;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
@@ -73,40 +74,39 @@ public class CompositeHealthCheck implements HealthCheck {
     
     @Override
     public Result execute() {
-        final Result result = new Result(log);
+        final FormattingResultLog resultLog = new FormattingResultLog();
         final List<HealthCheck> checks = new HealthCheckFilter(bundleContext).getTaggedHealthCheck(filterTags);
         if(checks.size() == 0) {
-            result.log(ResultLogEntry.LT_WARN, "HealthCheckFilter returns no HealthCheck for tags " + Arrays.asList(filterTags));
-            return result;
+            resultLog.warn("HealthCheckFilter returns no HealthCheck for tags {}", Arrays.asList(filterTags));
+            return new Result(resultLog);
         }
-            
-        result.log(ResultLogEntry.LT_DEBUG, 
-                "Executing " + checks.size() 
-                + " HealthCheck selected by the " + Arrays.asList(filterTags) + " tags");
+
+        int executed = 0;
+        resultLog.debug("Executing {} HealthCheck selected by the {} tags", checks.size(), Arrays.asList(filterTags));
         int failures = 0;
         for(HealthCheck hc : checks) {
             if(hc == this) {
-                result.log(ResultLogEntry.LT_WARN, 
-                        "Cowardly forfeiting execution of this HealthCheck in an infinite loop - do not include my tags in the filter tags!");
+                resultLog.info("Cowardly forfeiting execution of this HealthCheck in an infinite loop, ignoring it");
                 continue;
             }
-            result.log(ResultLogEntry.LT_DEBUG, "Executing " + hc); 
+            resultLog.debug("Executing {}", hc);
+            executed++;
             final Result sub = hc.execute();
             if(!sub.isOk()) {
                 failures++;
             }
-            result.merge(sub);
+            for(ResultLog.Entry e : sub) {
+                resultLog.add(e);
+            }
         }
         
         if(failures == 0) {
-            result.log(ResultLogEntry.LT_DEBUG, 
-                    checks.size() + " HealthCheck executed, all ok"); 
+            resultLog.debug("{} HealthCheck executed, all ok", executed);
         } else {
-            result.log(ResultLogEntry.LT_WARN, 
-                    checks.size() + " HealthCheck executed, " + failures + " failures"); 
+            resultLog.warn("{} HealthCheck executed, {} failures", executed, failures);
         }
         
-        return result;
+        return new Result(resultLog);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
index 357c5c1..d7196a9 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/DefaultLoginsHealthCheck.java
@@ -36,7 +36,7 @@ import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
@@ -80,14 +80,14 @@ public class DefaultLoginsHealthCheck implements HealthCheck {
     
     @Override
     public Result execute() {
-        final Result result = new Result(log);
+        final FormattingResultLog resultLog = new FormattingResultLog();
         int checked=0;
         int failures=0;
         
         for(String login : logins) {
             final String [] parts = login.split(":");
             if(parts.length != 2) {
-                result.log(ResultLogEntry.LT_WARN, "Expected login in the form username:password, got " + login);
+                resultLog.warn("Expected login in the form username:password, got [{}]", login);
                 continue;
             }
             checked++;
@@ -99,12 +99,12 @@ public class DefaultLoginsHealthCheck implements HealthCheck {
                 s = repository.login(creds);
                 if(s != null) {
                     failures++;
-                    result.log(ResultLogEntry.LT_WARN_SECURITY, "Login as [" + username + "] succeeded, was expecting it to fail");
+                    resultLog.warn("Login as [{}] succeeded, was expecting it to fail", username);
                 } else {
-                    result.log(ResultLogEntry.LT_DEBUG, "Login as [" + username + "] didn't throw an Exception but returned null Session");
+                    resultLog.debug("Login as [{}] didn't throw an Exception but returned null Session", username);
                 }
             } catch(RepositoryException re) {
-                result.log(ResultLogEntry.LT_DEBUG, "Login as [" + username + "] failed, as expected");
+                resultLog.debug("Login as [{}] failed, as expected", username);
             } finally {
                 if(s != null) {
                     s.logout();
@@ -113,13 +113,13 @@ public class DefaultLoginsHealthCheck implements HealthCheck {
         }
         
         if(checked==0) {
-            result.log(ResultLogEntry.LT_WARN, "Did not check any logins, configured logins=" + logins);
+            resultLog.warn("Did not check any logins, configured logins={}", logins);
         } else if(failures != 0){
-            result.log(ResultLogEntry.LT_WARN_SECURITY, "Checked " + checked + " logins, " + failures + " tests failed");
+            resultLog.warn("Checked {} logins, {} failures", checked, failures);
         } else {
-            result.log(ResultLogEntry.LT_DEBUG, "Checked " + checked + " logins, all tests successful");
+            resultLog.debug("Checked {} logins, all successful", checked, failures);
         }
-        return result;
+        return new Result(resultLog);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
index 6e72e5d..f2ab2e4 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxAttributeHealthCheck.java
@@ -32,12 +32,11 @@ import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.apache.sling.hc.util.SimpleConstraintChecker;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.helpers.MessageFormatter;
 
 /** {@link HealthCheck} that checks a single JMX attribute */
 @Component(
@@ -89,10 +88,8 @@ public class JmxAttributeHealthCheck implements HealthCheck {
     
     @Override
     public Result execute() {
-        final Result result = new Result(log);
-        result.log(ResultLogEntry.LT_DEBUG, 
-                MessageFormatter.arrayFormat("Checking {} / {} with constraint {}", 
-                        new Object[] { mbeanName, attributeName, constraint }).getMessage());
+        final FormattingResultLog resultLog = new FormattingResultLog();
+        resultLog.debug("Checking {} / {} with constraint {}", mbeanName, attributeName, constraint);
         try {
             final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
             final ObjectName objectName = new ObjectName(mbeanName);
@@ -100,15 +97,13 @@ public class JmxAttributeHealthCheck implements HealthCheck {
                 log.error("MBean not found: {}", objectName);
             }
             final Object value = jmxServer.getAttribute(objectName, attributeName);
-            result.log(ResultLogEntry.LT_DEBUG,
-                    MessageFormatter.arrayFormat( 
-                    "{} {} returns {}", 
-                    new Object[] { mbeanName, attributeName, value }).getMessage());
-            new SimpleConstraintChecker().check(value, constraint, result);
+            resultLog.debug("{} {} returns {}", mbeanName, attributeName, value);
+            new SimpleConstraintChecker().check(value, constraint, resultLog);
         } catch(Exception e) {
-            log.warn(e.toString(), e);
+            log.warn("JMX attribute {}/{} check failed: {}", new Object []{ mbeanName, attributeName, e});
+            resultLog.healthCheckError("JMX attribute check failed: {}", e);
         }
-        return result;
+        return new Result(resultLog);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxScriptBinding.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxScriptBinding.java
index 6773c56..463a38e 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxScriptBinding.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/JmxScriptBinding.java
@@ -27,9 +27,7 @@ import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
 
-import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
-import org.slf4j.helpers.MessageFormatter;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 
 /** The JmxBinding is meant to be bound as "jmx" global variables
  *  in scripted rules, to allow for writing scripted expressions
@@ -37,10 +35,10 @@ import org.slf4j.helpers.MessageFormatter;
  */
 public class JmxScriptBinding {
     private MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
-    private final Result result;
+    private final FormattingResultLog resultLog;
     
-    public JmxScriptBinding(Result result) {
-        this.result = result;
+    public JmxScriptBinding(FormattingResultLog resultLog) {
+        this.resultLog = resultLog;
     }
     
     public Object attribute(String objectNameString, String attributeName) 
@@ -48,15 +46,12 @@ public class JmxScriptBinding {
         final ObjectName name = new ObjectName(objectNameString);
         if(jmxServer.queryNames(name, null).size() == 0) {
             final String msg = "JMX object name not found: [" + objectNameString + "]";
-            result.log(ResultLogEntry.LT_WARN, msg);
+            resultLog.warn(msg);
             throw new IllegalStateException(msg);
         }
-        result.log(ResultLogEntry.LT_DEBUG, MessageFormatter.format("Got JMX Object [{}]", name).getMessage());
+        resultLog.debug("Got JMX Object [{}]", name);
         final Object value = jmxServer.getAttribute(name, attributeName);
-        result.log(ResultLogEntry.LT_DEBUG, 
-                MessageFormatter.arrayFormat(
-                        "JMX Object [{}] Attribute [{}] = [{}]", 
-                        new Object[] { name, attributeName, value }).getMessage());
+        resultLog.debug("JMX Object [{}] Attribute [{}] = [{}]", name, attributeName, value);
         return value;
     }
 }
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/OsgiScriptBinding.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/OsgiScriptBinding.java
index 29f80db..a34f8c9 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/OsgiScriptBinding.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/OsgiScriptBinding.java
@@ -17,23 +17,21 @@
  */
 package org.apache.sling.hc.healthchecks.impl;
 
-import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.slf4j.helpers.MessageFormatter;
 
 /** The OsgiBinding is meant to be bound as an "osgi" global variable
  *  in scripted rules, to allow for checking some OSGi states in
  *  a simple way
  */
 public class OsgiScriptBinding {
-    private final Result result;
+    private final FormattingResultLog resultLog;
     private final BundleContext bundleContext;
     
-    public OsgiScriptBinding(BundleContext ctx, Result result) {
-        this.result = result;
+    public OsgiScriptBinding(BundleContext ctx, FormattingResultLog resultLog) {
+        this.resultLog = resultLog;
         this.bundleContext = ctx;
     }
     
@@ -44,7 +42,7 @@ public class OsgiScriptBinding {
                 count++;
             }
         }
-        result.log(ResultLogEntry.LT_DEBUG, MessageFormatter.format("inactiveBundlesCount={}", count).getMessage());
+        resultLog.debug("inactiveBundlesCount={}", count);
         return count;
     }
     
@@ -52,10 +50,7 @@ public class OsgiScriptBinding {
         boolean active = true;
         if(!isFragment(b) && Bundle.ACTIVE != b.getState()) {
             active = false;
-            result.log(ResultLogEntry.LT_INFO, 
-                    MessageFormatter.arrayFormat(
-                            "Bundle {} is not active, state={} ({})", 
-                            new Object[] { b.getSymbolicName(), b.getState(), b.getState()}).getMessage());
+            resultLog.info("Bundle {} is not active, state={} ({})", b.getSymbolicName(), b.getState(), b.getState());
         }
         return active;
     }
@@ -63,8 +58,7 @@ public class OsgiScriptBinding {
     private boolean isFragment(Bundle b) {
         final String header = (String) b.getHeaders().get( Constants.FRAGMENT_HOST );
         if(header!= null && header.trim().length() > 0) {
-            result.log(ResultLogEntry.LT_DEBUG, 
-                    MessageFormatter.format("{} is a fragment bundle, state won't be checked", b).getMessage());
+            resultLog.debug("{} is a fragment bundle, state won't be checked", b);
             return true;
         } else {
             return false;
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
index 6e5d82f..5979baa 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/ScriptableHealthCheck.java
@@ -32,12 +32,11 @@ import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.helpers.MessageFormatter;
 
 /** {@link HealthCheck} that checks a scriptable expression */
 @Component(
@@ -89,39 +88,30 @@ public class ScriptableHealthCheck implements HealthCheck {
     
     @Override
     public Result execute() {
-        final Result result = new Result(log);
-        result.log(ResultLogEntry.LT_DEBUG, 
-                MessageFormatter.format(
-                        "Checking expression [{}], language extension=[{}]", 
-                        expression, languageExtension).getMessage());
+        final FormattingResultLog resultLog = new FormattingResultLog();
+        resultLog.debug("Checking expression [{}], language extension=[{}]",  expression, languageExtension);
         try {
             final ScriptEngine engine = scriptEngineManager.getEngineByExtension(languageExtension);
             if(engine == null) {
-                result.log(ResultLogEntry.LT_WARN, 
-                        MessageFormatter.format(
-                                "No ScriptEngine available for extension {}", 
-                                languageExtension).getMessage());
+                resultLog.healthCheckError("No ScriptEngine available for extension {}", languageExtension);
             } else {
                 // TODO pluggable Bindings? Reuse the Sling bindings providers?
                 final Bindings b = engine.createBindings();
-                b.put("jmx", new JmxScriptBinding(result));
-                b.put("osgi", new OsgiScriptBinding(bundleContext, result));
+                b.put("jmx", new JmxScriptBinding(resultLog));
+                b.put("osgi", new OsgiScriptBinding(bundleContext, resultLog));
                 final Object value = engine.eval(expression, b);
                 if(value!=null && "true".equals(value.toString())) {
-                    result.log(ResultLogEntry.LT_DEBUG, 
-                            MessageFormatter.format(
-                                    "Expression [{}] evaluates to true as expected", expression).getMessage());
+                    resultLog.debug("Expression [{}] evaluates to true as expected", expression);
                 } else {
-                    result.log(ResultLogEntry.LT_WARN, 
-                            MessageFormatter.format(
-                                    "Expression [{}] does not evaluate to true, value={}", 
-                                    expression, value).getMessage());
+                    resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value); 
                 }
             }
         } catch(Exception e) {
-            result.log(ResultLogEntry.LT_WARN, e.toString()); 
+            resultLog.healthCheckError(
+                    "Exception while evaluating expression [{}] with language extension [{}]: {}", 
+                    expression, languageExtension, e); 
         }
-        return result;
+        return new Result(resultLog);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java b/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
index 32fd6d4..8b8f2c4 100644
--- a/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
+++ b/src/main/java/org/apache/sling/hc/healthchecks/impl/SlingRequestStatusHealthCheck.java
@@ -35,11 +35,10 @@ import org.apache.sling.engine.SlingRequestProcessor;
 import org.apache.sling.hc.api.Constants;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.ResultLogEntry;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.helpers.MessageFormatter;
 
 /** {@link HealthCheck} that checks the HTTP status of Sling requests */
 @Component(
@@ -101,15 +100,17 @@ public class SlingRequestStatusHealthCheck implements HealthCheck {
     
     @Override
     public Result execute() {
-        final Result result = new Result(log);
+        final FormattingResultLog resultLog = new FormattingResultLog();
         
         ResourceResolver resolver = null;
         int checked = 0;
         int failed = 0;
+        String lastPath = null;
         
         try {
             resolver = resolverFactory.getAdministrativeResourceResolver(null);
             for(String p : paths) {
+                lastPath = p;
                 final PathSpec ps = new PathSpec(p);
                 final HttpServletRequest request = new InternalRequest(ps.path);
                 final InternalResponse response = new InternalResponse();
@@ -117,18 +118,14 @@ public class SlingRequestStatusHealthCheck implements HealthCheck {
                 final int status = response.getStatus();
                 if(status != ps.status) {
                     failed++;
-                    result.log(ResultLogEntry.LT_WARN,
-                            MessageFormatter.arrayFormat(
-                            "[{}] returns status {}, expected {}", new Object[] { ps.path, status, ps.status }).getMessage());
+                    resultLog.warn("[{}] returns status {}, expected {}", new Object[] { ps.path, status, ps.status });
                 } else {
-                    result.log(ResultLogEntry.LT_DEBUG,
-                            MessageFormatter.format(
-                            "[{}] returns status {} as expected", ps.path, status).getMessage());
+                    resultLog.debug("[{}] returns status {} as expected", ps.path, status);
                 }
                 checked++;
             }
         } catch(Exception e) {
-            result.log(ResultLogEntry.LT_WARN, "Exception while executing request: " + e.toString());
+            resultLog.warn("Exception while executing request [{}]: {}", lastPath, e);
         } finally {
             if(resolver != null) {
                 resolver.close();
@@ -136,14 +133,12 @@ public class SlingRequestStatusHealthCheck implements HealthCheck {
         }
         
         if(checked == 0) {
-            result.log(ResultLogEntry.LT_WARN, "No paths checked, empty paths list?");
+            resultLog.warn("No paths checked, empty paths list?");
         } else {
-            result.log(ResultLogEntry.LT_DEBUG, 
-                    MessageFormatter.format(
-                            "{} paths checked, {} failures", checked, failed).getMessage());
+            resultLog.debug("{} paths checked, {} failures", checked, failed);
         }
         
-        return result;
+        return new Result(resultLog);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/hc/healthchecks/util/FormattingResultLog.java b/src/main/java/org/apache/sling/hc/healthchecks/util/FormattingResultLog.java
new file mode 100644
index 0000000..6933f08
--- /dev/null
+++ b/src/main/java/org/apache/sling/hc/healthchecks/util/FormattingResultLog.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.healthchecks.util;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.api.ResultLog;
+import org.slf4j.helpers.MessageFormatter;
+
+/** Utility that provides a logging-like facade on a ResultLog */
+public class FormattingResultLog extends ResultLog {
+    
+    private ResultLog.Entry createEntry(Result.Status status, String format, Object ... args) {
+        return new ResultLog.Entry(status, MessageFormatter.arrayFormat(format, args).getMessage());
+    }
+    
+    public void debug(String format, Object ... args) {
+        add(createEntry(Result.Status.DEBUG, format, args));
+    }
+    
+    public void info(String format, Object ... args) {
+        add(createEntry(Result.Status.INFO, format, args));
+    }
+    
+    public void warn(String format, Object ... args) {
+        add(createEntry(Result.Status.WARN, format, args));
+    }
+    
+    public void critical(String format, Object ... args) {
+        add(createEntry(Result.Status.CRITICAL, format, args));
+    }
+
+    public void healthCheckError(String format, Object ... args) {
+        add(createEntry(Result.Status.HEALTH_CHECK_ERROR, format, args));
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/hc/healthchecks/JmxScriptBindingTest.java b/src/test/java/org/apache/sling/hc/healthchecks/JmxScriptBindingTest.java
index 7cad43b..8886c11 100644
--- a/src/test/java/org/apache/sling/hc/healthchecks/JmxScriptBindingTest.java
+++ b/src/test/java/org/apache/sling/hc/healthchecks/JmxScriptBindingTest.java
@@ -20,20 +20,16 @@ package org.apache.sling.hc.healthchecks;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.healthchecks.impl.JmxScriptBinding;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class JmxScriptBindingTest {
     
-    private final Logger logger = LoggerFactory.getLogger(getClass());
-    
     @Test
     public void testJmxAttribute() throws Exception {
-        final Result r = new Result(logger);
-        final JmxScriptBinding b = new JmxScriptBinding(r);
+        final FormattingResultLog resultLog = new FormattingResultLog();
+        final JmxScriptBinding b = new JmxScriptBinding(resultLog);
         final Object value= b.attribute("java.lang:type=ClassLoading", "LoadedClassCount");
         assertNotNull("Expecting non-null attribute value", value);
         assertTrue("Expecting non-empty value", value.toString().length() > 0);
diff --git a/src/test/java/org/apache/sling/hc/healthchecks/OsgiScriptBindingTest.java b/src/test/java/org/apache/sling/hc/healthchecks/OsgiScriptBindingTest.java
index b9dcf83..731c7d9 100644
--- a/src/test/java/org/apache/sling/hc/healthchecks/OsgiScriptBindingTest.java
+++ b/src/test/java/org/apache/sling/hc/healthchecks/OsgiScriptBindingTest.java
@@ -22,20 +22,16 @@ import static org.junit.Assert.assertEquals;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.healthchecks.impl.OsgiScriptBinding;
+import org.apache.sling.hc.healthchecks.util.FormattingResultLog;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class OsgiScriptBindingTest {
     
-    private final Logger logger = LoggerFactory.getLogger(getClass());
-    
     private Bundle mockBundle(boolean isFragment, boolean isActive) {
         final Bundle b = Mockito.mock(Bundle.class);
         Mockito.when(b.getState()).thenReturn(isActive ? Bundle.ACTIVE : Bundle.RESOLVED);
@@ -60,8 +56,8 @@ public class OsgiScriptBindingTest {
         };
         Mockito.when(ctx.getBundles()).thenReturn(bundles);
         
-        final Result r = new Result(logger);
-        final OsgiScriptBinding b = new OsgiScriptBinding(ctx, r);
+        final FormattingResultLog resultLog = new FormattingResultLog();
+        final OsgiScriptBinding b = new OsgiScriptBinding(ctx, resultLog);
         assertEquals(1, b.inactiveBundlesCount());
     }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.