1 11 package org.eclipse.core.internal.runtime; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 import org.eclipse.core.runtime.*; 16 import org.osgi.framework.Bundle; 17 18 21 public class Log implements ILog { 22 Bundle bundle; 23 Set logListeners = new HashSet (5); 24 25 public Log(Bundle plugin) { 26 this.bundle = plugin; 27 } 28 29 35 public void addLogListener(ILogListener listener) { 36 synchronized (logListeners) { 37 logListeners.add(listener); 38 } 39 } 40 41 44 public Bundle getBundle() { 45 return bundle; 46 } 47 48 54 public void log(final IStatus status) { 55 InternalPlatform.getDefault().log(status); 57 ILogListener[] listeners; 59 synchronized (logListeners) { 60 listeners = (ILogListener[]) logListeners.toArray(new ILogListener[logListeners.size()]); 61 } 62 for (int i = 0; i < listeners.length; i++) { 63 final ILogListener listener = listeners[i]; 64 ISafeRunnable code = new ISafeRunnable() { 65 public void run() throws Exception { 66 listener.logging(status, bundle.getSymbolicName()); 67 } 68 69 public void handleException(Throwable e) { 70 } 72 }; 73 SafeRunner.run(code); 74 } 75 } 76 77 83 public void removeLogListener(ILogListener listener) { 84 synchronized (logListeners) { 85 logListeners.remove(listener); 86 } 87 } 88 } 89 | Popular Tags |