Search in sources :

Example 1 with ExtendedLogService

use of org.eclipse.equinox.log.ExtendedLogService in project rt.equinox.framework by eclipse.

the class SystemBundleTests method doLoggingOnMultipleListeners.

public static void doLoggingOnMultipleListeners(Equinox equinox) throws InterruptedException {
    int listenersSize = 100;
    int logSize = 10000;
    BundleContext bc = equinox.getBundleContext();
    ExtendedLogReaderService logReader = bc.getService(bc.getServiceReference(ExtendedLogReaderService.class));
    ExtendedLogService log = bc.getService(bc.getServiceReference(ExtendedLogService.class));
    ArrayList<TestListener2> listeners = new ArrayList<TestListener2>();
    CountDownLatch latch = new CountDownLatch(logSize * listenersSize);
    for (int i = 0; i < listenersSize; i++) {
        TestListener2 listener = new TestListener2(latch);
        listeners.add(listener);
        logReader.addLogListener(listener);
    }
    for (int i = 0; i < logSize; i++) {
        log.warn(String.valueOf(i));
    }
    latch.await(10, TimeUnit.SECONDS);
    assertEquals("Failed to log all entries", 0, latch.getCount());
    int expected = 0;
    for (String msg : listeners.get(0).getLogs()) {
        assertEquals("Unexpected log found.", expected, Integer.parseInt(msg));
        expected++;
    }
    for (int i = 1; i < listenersSize; i++) {
        assertTrue(listeners.get(i).getLogs().equals(listeners.get(0).getLogs()));
    }
}
Also used : ExtendedLogReaderService(org.eclipse.equinox.log.ExtendedLogReaderService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) TestListener2(org.eclipse.equinox.log.test.TestListener2) ExtendedLogService(org.eclipse.equinox.log.ExtendedLogService) CountDownLatch(java.util.concurrent.CountDownLatch) BundleContext(org.osgi.framework.BundleContext)

Example 2 with ExtendedLogService

use of org.eclipse.equinox.log.ExtendedLogService in project rt.equinox.framework by eclipse.

the class ExtendedLogServiceImpl method getLogger.

public Logger getLogger(Bundle logBundle, String name) {
    if (logBundle == null || logBundle == bundle)
        return getLogger(name);
    // only check permission if getting another bundles log
    factory.checkLogPermission();
    ExtendedLogService bundleLogService = factory.getLogService(logBundle);
    return bundleLogService.getLogger(name);
}
Also used : ExtendedLogService(org.eclipse.equinox.log.ExtendedLogService)

Aggregations

ExtendedLogService (org.eclipse.equinox.log.ExtendedLogService)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExtendedLogReaderService (org.eclipse.equinox.log.ExtendedLogReaderService)1 TestListener2 (org.eclipse.equinox.log.test.TestListener2)1 BundleContext (org.osgi.framework.BundleContext)1