sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1651758 - /sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java
Date Wed, 14 Jan 2015 18:11:37 GMT
Author: chetanm
Date: Wed Jan 14 18:11:36 2015
New Revision: 1651758

URL: http://svn.apache.org/r1651758
Log:
SLING-4280 - Enable dumping of remote server logs in case of test failures

Detect the case when running with slf4j-simple which does not have function MDC support and
log a warning in that case

Modified:
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java?rev=1651758&r1=1651757&r2=1651758&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/junit/RemoteLogDumper.java
Wed Jan 14 18:11:36 2015
@@ -30,6 +30,7 @@ import org.apache.sling.testing.tools.sl
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
 import org.slf4j.MDC;
+import org.slf4j.spi.MDCAdapter;
 
 /**
  * The RemoteLogDumper Rule fetches logs which are generated due to execution of test from
the
@@ -80,6 +81,7 @@ public class RemoteLogDumper extends Tes
 
         if (baseUrl != null) {
             try {
+                warnIfNopMDCAdapterBeingUsed();
                 DefaultHttpClient httpClient = new DefaultHttpClient();
                 RequestExecutor executor = new RequestExecutor(httpClient);
                 RequestBuilder rb = new RequestBuilder(baseUrl);
@@ -115,6 +117,27 @@ public class RemoteLogDumper extends Tes
         }
     }
 
+    private static void warnIfNopMDCAdapterBeingUsed() {
+        try {
+            MDCAdapter adapter = MDC.getMDCAdapter();
+            String msg = null;
+            if (adapter == null) {
+                msg = "No MDC Adapter found.";
+            } else if ("org.slf4j.helpers.NOPMDCAdapter".equals(adapter.getClass().getName()))
{
+                msg = "MDC adapter set to [org.slf4j.helpers.NOPMDCAdapter].";
+            }
+
+            if (msg != null) {
+                System.err.printf("%s Possibly running with slf4j-simple. " +
+                        "Use Logging implementation like Logback to enable proper MDC support
so " +
+                        "as to make use of RemoteLogDumper feature.%n", msg);
+            }
+
+        } catch (Throwable ignore) {
+
+        }
+    }
+
     private static String getServerBaseUrl() {
         SlingInstanceState testState = SlingInstanceState.getInstance(SlingInstanceState.DEFAULT_INSTANCE_NAME);
         String baseUrl = testState.getServerBaseUrl();



Mime
View raw message