Search in sources :

Example 21 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class LogTracker method log.

public synchronized void log(ServiceReference reference, int level, String message, Throwable exception) {
    ServiceReference[] references = getServiceReferences();
    if (references != null) {
        int size = references.length;
        for (int i = 0; i < size; i++) {
            LogService service = (LogService) getService(references[i]);
            if (service != null) {
                try {
                    service.log(reference, level, message, exception);
                } catch (Exception e) {
                // TODO: consider printing to System Error
                }
            }
        }
        return;
    }
    noLogService(level, message, exception, reference);
}
Also used : LogService(org.osgi.service.log.LogService) ServiceReference(org.osgi.framework.ServiceReference)

Example 22 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class Activator method getLogService.

protected LogService getLogService() {
    if (logServiceTracker == null) {
        logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
        logServiceTracker.open();
    }
    return (LogService) logServiceTracker.getService();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) LogService(org.osgi.service.log.LogService)

Example 23 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class ProviderPlugin method getLogService.

@SuppressWarnings("unchecked")
protected LogService getLogService() {
    if (context == null) {
        if (systemLogService == null)
            systemLogService = new SystemLogService(PLUGIN_ID);
        return systemLogService;
    }
    if (logServiceTracker == null) {
        logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
        logServiceTracker.open();
    }
    return (LogService) logServiceTracker.getService();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) LogService(org.osgi.service.log.LogService)

Example 24 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class ChannelEndpointImpl method stopTiming.

void stopTiming(String message, Throwable exception) {
    if (TRACE_TIME) {
        StringBuffer buf = new StringBuffer("TIMING.END;");
        buf.append(sdf.format(new Date(startTime))).append(";");
        buf.append((message == null ? "" : message));
        buf.append(";duration(ms)=").append((System.currentTimeMillis() - startTime));
        LogService logService = RemoteOSGiServiceImpl.log;
        if (logService != null && USE_LOG_SERVICE) {
            if (exception != null)
                logService.log(LogService.LOG_ERROR, buf.toString(), exception);
            else
                logService.log(LogService.LOG_INFO, buf.toString());
        } else {
            System.out.println(buf.toString());
            if (exception != null)
                exception.printStackTrace();
        }
        startTime = 0;
    }
}
Also used : Date(java.util.Date) LogService(org.osgi.service.log.LogService)

Example 25 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class ChannelEndpointImpl method startTiming.

void startTiming(String message) {
    if (TRACE_TIME) {
        startTime = System.currentTimeMillis();
        StringBuffer buf = new StringBuffer("TIMING.START;");
        buf.append(sdf.format(new Date(startTime))).append(";");
        buf.append((message == null ? "" : message));
        LogService logService = RemoteOSGiServiceImpl.log;
        if (logService != null && USE_LOG_SERVICE)
            logService.log(LogService.LOG_INFO, buf.toString());
        else
            System.out.println(buf.toString());
    }
}
Also used : Date(java.util.Date) LogService(org.osgi.service.log.LogService)

Aggregations

LogService (org.osgi.service.log.LogService)57 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 File (java.io.File)10 ServiceReference (org.osgi.framework.ServiceReference)10 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)7 Bundle (org.osgi.framework.Bundle)7 HashMap (java.util.HashMap)6 PrintStream (java.io.PrintStream)5 StringWriter (java.io.StringWriter)5 Builder (aQute.bnd.osgi.Builder)4 Jar (aQute.bnd.osgi.Jar)4 Resource (aQute.bnd.osgi.Resource)4 XmlTester (aQute.bnd.test.XmlTester)4 Attributes (java.util.jar.Attributes)4 BundleInfoImpl (org.apache.felix.deploymentadmin.BundleInfoImpl)4 Before (org.junit.Before)4 BundleContext (org.osgi.framework.BundleContext)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Matchers.anyString (org.mockito.Matchers.anyString)3