Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java')
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java
new file mode 100644
index 0000000000..ade141c769
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Log.java
@@ -0,0 +1,113 @@
+package org.eclipse.internal.net4j.util.bundle;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+
+public final class Log
+{
+ private static ServiceTracker logTracker;
+
+ private Log()
+ {
+ };
+
+ static void init(BundleContext bc)
+ {
+ logTracker = new ServiceTracker(bc, LogService.class.getName(), null);
+ logTracker.open();
+ }
+
+ static void dispose()
+ {
+ if (logTracker != null)
+ {
+ logTracker.close();
+ logTracker = null;
+ }
+ }
+
+ public static void debug(String message)
+ {
+ log(LogService.LOG_DEBUG, message, null);
+ }
+
+ public static void debug(String message, Throwable t)
+ {
+ log(LogService.LOG_DEBUG, message, null);
+ }
+
+ public static void info(String message)
+ {
+ log(LogService.LOG_INFO, message, null);
+ }
+
+ public static void info(String message, Throwable t)
+ {
+ log(LogService.LOG_INFO, message, null);
+ }
+
+ public static void warn(String message)
+ {
+ log(LogService.LOG_WARNING, message, null);
+ }
+
+ public static void warn(String message, Throwable t)
+ {
+ log(LogService.LOG_WARNING, message, null);
+ }
+
+ public static void error(String message)
+ {
+ log(LogService.LOG_ERROR, message, null);
+ }
+
+ public static void error(String message, Throwable t)
+ {
+ log(LogService.LOG_ERROR, message, null);
+ }
+
+ public static void log(int level, String message)
+ {
+ log(level, message, null);
+ }
+
+ public static void log(int level, String message, Throwable t)
+ {
+ LogService logService = (LogService)logTracker.getService();
+ if (logService != null)
+ {
+ logService.log(level, message, t);
+ }
+ else
+ {
+ switch (level)
+ {
+ case LogService.LOG_DEBUG:
+ System.out.print("[DEBUG] ");
+ break;
+
+ case LogService.LOG_INFO:
+ System.out.print("[INFO] ");
+ break;
+
+ case LogService.LOG_WARNING:
+ System.out.print("[WARN] ");
+ break;
+
+ case LogService.LOG_ERROR:
+ System.out.print("[ERROR] ");
+ break;
+
+ default:
+ break;
+ }
+
+ System.out.println(message);
+ if (t != null)
+ {
+ t.printStackTrace();
+ }
+ }
+ }
+} \ No newline at end of file

Back to the top