Search in sources :

Example 1 with LogListener

use of org.osgi.service.log.LogListener in project rt.equinox.framework by eclipse.

the class OrderedExecutor method addLogListener.

void addLogListener(LogListener listener, LogFilter filter) {
    listenersLock.writeLock().lock();
    try {
        ArrayMap<LogListener, Object[]> listenersCopy = new ArrayMap<>(listeners.getKeys(), listeners.getValues());
        Object[] listenerObjects = listenersCopy.get(listener);
        if (listenerObjects == null) {
            // Only create a task queue for non-SynchronousLogListeners
            OrderedTaskQueue taskQueue = (listener instanceof SynchronousLogListener) ? null : executor.createQueue();
            listenerObjects = new Object[] { filter, taskQueue };
        } else if (filter != listenerObjects[0]) {
            // update the filter
            listenerObjects[0] = filter;
        }
        listenersCopy.put(listener, listenerObjects);
        recalculateFilters(listenersCopy);
        listeners = listenersCopy;
    } finally {
        listenersLock.writeLock().unlock();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) OrderedTaskQueue(org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue) ArrayMap(org.eclipse.osgi.framework.util.ArrayMap)

Example 2 with LogListener

use of org.osgi.service.log.LogListener in project rt.equinox.framework by eclipse.

the class OrderedExecutor method logPrivileged.

void logPrivileged(Bundle bundle, String name, StackTraceElement stackTraceElement, Object context, LogLevel logLevelEnum, int level, String message, Throwable exception) {
    LogEntry logEntry = new ExtendedLogEntryImpl(bundle, name, stackTraceElement, context, logLevelEnum, level, message, exception);
    storeEntry(logEntry);
    ArrayMap<LogListener, Object[]> listenersCopy;
    listenersLock.readLock().lock();
    try {
        listenersCopy = listeners;
    } finally {
        listenersLock.readLock().unlock();
    }
    try {
        if (incrementNestedCount() >= MAX_RECURSIONS)
            return;
        int size = listenersCopy.size();
        for (int i = 0; i < size; i++) {
            Object[] listenerObjects = listenersCopy.getValue(i);
            LogFilter filter = (LogFilter) listenerObjects[0];
            if (safeIsLoggable(filter, bundle, name, level)) {
                LogListener listener = listenersCopy.getKey(i);
                OrderedTaskQueue orderedTaskQueue = (OrderedTaskQueue) listenerObjects[1];
                if (orderedTaskQueue != null) {
                    orderedTaskQueue.execute(new LogTask(logEntry, listener), size);
                } else {
                    // log synchronously
                    safeLogged(listener, logEntry);
                }
            }
        }
    } finally {
        decrementNestedCount();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) OrderedTaskQueue(org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue) LogEntry(org.osgi.service.log.LogEntry) LogFilter(org.eclipse.equinox.log.LogFilter)

Example 3 with LogListener

use of org.osgi.service.log.LogListener in project rt.equinox.framework by eclipse.

the class ExtendedLogReaderServiceTest method testSynchronousLogListener.

public void testSynchronousLogListener() throws Exception {
    final Thread loggerThread = Thread.currentThread();
    called = false;
    LogListener listener = new SynchronousLogListener() {

        public void logged(LogEntry entry) {
            assertTrue(Thread.currentThread() == loggerThread);
            called = true;
        }
    };
    reader.addLogListener(listener);
    log.log(LogService.LOG_INFO, "info");
    assertTrue(called);
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogEntry(org.osgi.service.log.LogEntry) ExtendedLogEntry(org.eclipse.equinox.log.ExtendedLogEntry)

Aggregations

SynchronousLogListener (org.eclipse.equinox.log.SynchronousLogListener)3 LogListener (org.osgi.service.log.LogListener)3 OrderedTaskQueue (org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue)2 LogEntry (org.osgi.service.log.LogEntry)2 ExtendedLogEntry (org.eclipse.equinox.log.ExtendedLogEntry)1 LogFilter (org.eclipse.equinox.log.LogFilter)1 ArrayMap (org.eclipse.osgi.framework.util.ArrayMap)1