Register a default LogService in order to display logs from annotation stuff
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@918688 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/Base.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/Base.java
index 5cf73cf..859569a 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/Base.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/Base.java
@@ -19,21 +19,36 @@
package org.apache.felix.dm.test;
import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.net.URL;
import org.junit.After;
+import org.junit.Before;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
/**
* Base class for all test cases.
*/
-public class Base
+public class Base implements LogService
{
/**
+ * Register us as a LogService
+ * @param context
+ */
+ @Before
+ public void startup(BundleContext context)
+ {
+ context.registerService(LogService.class.getName(), this, null);
+ }
+
+ /**
* Always cleanup our bundle location file (because pax seems to forget to cleanup it)
* @param context
*/
- @After
+ @After
public void tearDown(BundleContext context)
{
try
@@ -46,4 +61,47 @@
t.printStackTrace();
}
}
+
+ public void log(int level, String message)
+ {
+ System.out.println("[LogService/" + level + "] " + message);
+ }
+
+ public void log(int level, String message, Throwable exception)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[LogService/" + level + "] ");
+ sb.append(message);
+ parse(sb, exception);
+ System.out.println(sb.toString());
+ }
+
+ public void log(ServiceReference sr, int level, String message)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[LogService/" + level + "] ");
+ sb.append(message);
+ System.out.println(sb.toString());
+ }
+
+ public void log(ServiceReference sr, int level, String message, Throwable exception)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[LogService/" + level + "] ");
+ sb.append(message);
+ parse(sb, exception);
+ System.out.println(sb.toString());
+ }
+
+ private void parse(StringBuilder sb, Throwable t)
+ {
+ if (t != null)
+ {
+ sb.append(" - ");
+ StringWriter buffer = new StringWriter();
+ PrintWriter pw = new PrintWriter(buffer);
+ t.printStackTrace(pw);
+ sb.append(buffer.toString());
+ }
+ }
}