Search in sources :

Example 1 with LogFilter

use of org.eclipse.equinox.log.LogFilter 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 2 with LogFilter

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

the class OrderedExecutor method recalculateFilters.

private void recalculateFilters(ArrayMap<LogListener, Object[]> listenersCopy) {
    List<LogFilter> filtersList = new ArrayList<>();
    int size = listenersCopy.size();
    for (int i = 0; i < size; i++) {
        Object[] listenerObjects = listenersCopy.getValue(i);
        LogFilter filter = (LogFilter) listenerObjects[0];
        if (filter == NULL_LOGGER_FILTER) {
            filters = ALWAYS_LOG;
            return;
        }
        filtersList.add(filter);
    }
    if (filtersList.isEmpty())
        filters = null;
    filters = filtersList.toArray(new LogFilter[filtersList.size()]);
}
Also used : ArrayList(java.util.ArrayList) LogFilter(org.eclipse.equinox.log.LogFilter)

Example 3 with LogFilter

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

the class OrderedExecutor method isLoggablePrivileged.

boolean isLoggablePrivileged(Bundle bundle, String name, int level) {
    LogFilter[] filtersCopy;
    listenersLock.readLock().lock();
    try {
        filtersCopy = filters;
    } finally {
        listenersLock.readLock().unlock();
    }
    try {
        if (incrementNestedCount() == MAX_RECURSIONS)
            return false;
        if (filtersCopy == null)
            return false;
        if (filtersCopy == ALWAYS_LOG)
            return true;
        int filtersLength = filtersCopy.length;
        for (int i = 0; i < filtersLength; i++) {
            LogFilter filter = filtersCopy[i];
            if (safeIsLoggable(filter, bundle, name, level))
                return true;
        }
    } finally {
        decrementNestedCount();
    }
    return false;
}
Also used : LogFilter(org.eclipse.equinox.log.LogFilter)

Example 4 with LogFilter

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

the class ExtendedLogReaderServiceTest method testaddFilteredListenerTwice.

public void testaddFilteredListenerTwice() throws Exception {
    TestListener listener = new TestListener();
    reader.addLogListener(listener, new LogFilter() {

        public boolean isLoggable(Bundle b, String loggerName, int logLevel) {
            return false;
        }
    });
    if (log.isLoggable(LogService.LOG_INFO))
        fail();
    reader.addLogListener(listener, new LogFilter() {

        public boolean isLoggable(Bundle b, String loggerName, int logLevel) {
            return true;
        }
    });
    synchronized (listener) {
        log.log(LogService.LOG_INFO, "info");
        listener.waitForLogEntry();
    }
    assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
Also used : Bundle(org.osgi.framework.Bundle) LogFilter(org.eclipse.equinox.log.LogFilter)

Example 5 with LogFilter

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

the class ExtendedLogReaderServiceTest method testaddFilteredListener.

public void testaddFilteredListener() throws Exception {
    TestListener listener = new TestListener();
    reader.addLogListener(listener, new LogFilter() {

        public boolean isLoggable(Bundle b, String loggerName, int logLevel) {
            return true;
        }
    });
    synchronized (listener) {
        log.log(LogService.LOG_INFO, "info");
        listener.waitForLogEntry();
    }
    assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
Also used : Bundle(org.osgi.framework.Bundle) LogFilter(org.eclipse.equinox.log.LogFilter)

Aggregations

LogFilter (org.eclipse.equinox.log.LogFilter)6 Bundle (org.osgi.framework.Bundle)3 ArrayList (java.util.ArrayList)1 SynchronousLogListener (org.eclipse.equinox.log.SynchronousLogListener)1 OrderedTaskQueue (org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue)1 LogEntry (org.osgi.service.log.LogEntry)1 LogListener (org.osgi.service.log.LogListener)1