Search in sources :

Example 11 with LogEntry

use of org.osgi.service.log.LogEntry in project felix by apache.

the class LogNodeEnumeration method nextElement.

/**
 * Returns the current element and moves onto the next element.
 * @return the current element
 */
public Object nextElement() {
    LogEntry result = null;
    if (m_next == m_last) {
        result = m_next.getEntry();
        m_next = null;
    } else if (m_next != null) {
        result = m_next.getEntry();
        m_next = m_next.getNextNode();
    }
    return result;
}
Also used : LogEntry(org.osgi.service.log.LogEntry)

Example 12 with LogEntry

use of org.osgi.service.log.LogEntry in project felix by apache.

the class LogCommandImpl method execute.

public void execute(String line, PrintStream out, PrintStream err) {
    LogOptions options = new LogOptions(line);
    ServiceReference ref = m_bundleContext.getServiceReference(LogReaderService.class.getName());
    if (ref != null) {
        LogReaderService service = (LogReaderService) m_bundleContext.getService(ref);
        Enumeration entries = service.getLog();
        int index = 0;
        while (entries.hasMoreElements() && (options.getMaxNumberOfLogs() < 0 | index < options.getMaxNumberOfLogs())) {
            LogEntry entry = (LogEntry) entries.nextElement();
            if (entry.getLevel() <= options.getMinLevel()) {
                display(entry, out);
                index++;
            }
        }
    } else {
        out.println("No LogReaderService available");
    }
}
Also used : Enumeration(java.util.Enumeration) LogReaderService(org.osgi.service.log.LogReaderService) LogEntry(org.osgi.service.log.LogEntry) ServiceReference(org.osgi.framework.ServiceReference)

Example 13 with LogEntry

use of org.osgi.service.log.LogEntry in project bnd by bndtools.

the class TestingLog method check.

public boolean check(String... patterns) {
    if (entries.isEmpty())
        return true;
    int n = entries.size();
    for (LogEntry le : entries) {
        for (String pattern : patterns) {
            if (le.getMessage().contains(pattern))
                n--;
            else
                System.out.println(le);
        }
    }
    entries.clear();
    return n != 0;
}
Also used : LogEntry(org.osgi.service.log.LogEntry)

Example 14 with LogEntry

use of org.osgi.service.log.LogEntry 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 15 with LogEntry

use of org.osgi.service.log.LogEntry 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

LogEntry (org.osgi.service.log.LogEntry)40 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)6 LogReaderService (org.osgi.service.log.LogReaderService)5 BundleException (org.osgi.framework.BundleException)4 Enumeration (java.util.Enumeration)3 ServiceReference (org.osgi.framework.ServiceReference)3 LogListener (org.osgi.service.log.LogListener)3 SynchronousLogListener (org.eclipse.equinox.log.SynchronousLogListener)2 BundleContext (org.osgi.framework.BundleContext)2 TestDriver (com.yahoo.jdisc.test.TestDriver)1 File (java.io.File)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Vector (java.util.Vector)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1