Search in sources :

Example 26 with LogEntry

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

the class LogSupportTest method testInfoLogger.

@Test
public void testInfoLogger() throws Exception {
    LogEntry le = new LogEntryImpl(bundle, null, LogService.LOG_INFO, "my-info-message", null);
    logSupport.fireLogEvent(le);
    Mockito.verify(testLogger).info("my-info-message", (Throwable) null);
}
Also used : LogEntry(org.osgi.service.log.LogEntry) Test(org.junit.Test)

Example 27 with LogEntry

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

the class LogServlet method renderJSON.

private final void renderJSON(final PrintWriter pw, int minLogLevel, boolean traces) throws IOException {
    // create status line
    final LogReaderService logReaderService = (LogReaderService) this.getService(LogReaderService.class.getName());
    JSONWriter jw = new JSONWriter(pw);
    jw.object();
    // $NON-NLS-1$
    jw.key("status");
    jw.value(logReaderService == null ? Boolean.FALSE : Boolean.TRUE);
    // $NON-NLS-1$
    jw.key("data");
    jw.array();
    if (logReaderService != null) {
        int index = 0;
        for (Enumeration logEntries = logReaderService.getLog(); logEntries.hasMoreElements() && index < MAX_LOGS; ) {
            LogEntry nextLog = (LogEntry) logEntries.nextElement();
            if (nextLog.getLevel() <= minLogLevel) {
                logJson(jw, nextLog, index++, traces);
            }
        }
    }
    jw.endArray();
    jw.endObject();
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) Enumeration(java.util.Enumeration) LogReaderService(org.osgi.service.log.LogReaderService) LogEntry(org.osgi.service.log.LogEntry)

Example 28 with LogEntry

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

the class TestManifestLoggerInfo method getMessages.

private List<String> getMessages(Enumeration<LogEntry> log2) {
    List<String> list = new ArrayList<String>();
    while (log2.hasMoreElements()) {
        LogEntry entry = (LogEntry) log2.nextElement();
        list.add(entry.getMessage());
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) LogEntry(org.osgi.service.log.LogEntry)

Example 29 with LogEntry

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

the class Logger method sendOldLog.

// ///////////////////////////////
// LogerMBean Interface    //
// ///////////////////////////////
public void sendOldLog() {
    System.out.println("[remoteLogger.Logger] send old log");
    Enumeration oldLog = this.lrs.getLog();
    Vector invert = new Vector();
    while (oldLog.hasMoreElements()) {
        LogEntry le = (LogEntry) (oldLog.nextElement());
        invert.insertElementAt(le, 0);
    }
    for (int i = 0; i < invert.size(); i++) {
        logged((LogEntry) invert.elementAt(i), true);
    }
}
Also used : Enumeration(java.util.Enumeration) Vector(java.util.Vector) LogEntry(org.osgi.service.log.LogEntry)

Example 30 with LogEntry

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

the class Log method serviceChanged.

/**
 * Called when a service event occurs.
 * @param event the event that occured
 */
public void serviceChanged(final ServiceEvent event) {
    int eventType = event.getType();
    String message = null;
    for (int i = 0; message == null && i < SERVICE_EVENT_MESSAGES.length; ++i) {
        if (eventType >> i == 1) {
            message = SERVICE_EVENT_MESSAGES[i];
        }
    }
    LogEntry entry = new LogEntryImpl(event.getServiceReference().getBundle(), event.getServiceReference(), (eventType == ServiceEvent.MODIFIED) ? LogService.LOG_DEBUG : LogService.LOG_INFO, message, null);
    addEntry(entry);
}
Also used : LogEntry(org.osgi.service.log.LogEntry)

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