當前位置: 首頁>>代碼示例>>Java>>正文


Java LogService.log方法代碼示例

本文整理匯總了Java中org.osgi.service.log.LogService.log方法的典型用法代碼示例。如果您正苦於以下問題:Java LogService.log方法的具體用法?Java LogService.log怎麽用?Java LogService.log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.service.log.LogService的用法示例。


在下文中一共展示了LogService.log方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void run() {

      while (Thread.currentThread() == m_logTestThread) {

        // query the listener to find the best matching service
        LogService logService = m_logListener.getLogService();

        // if the service instance is null then we know there is no LogService available
        if (logService != null) {
          try {
            logService.log(LogService.LOG_INFO, "ping");
          } catch (RuntimeException re) {
            alternativeLog("error in LogService " + re);
          }
        } else {
          alternativeLog("LogService has gone");
        }

        pauseTestThread();
      }
    }
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:22,代碼來源:Activator.java

示例2: run

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void run() {

      while (Thread.currentThread() == m_logTestThread) {
        // query the tracker to find the best matching service
        LogService logService = (LogService) m_logTracker.getService();

        // if the service instance is null then we know there is no LogService available
        if (logService != null) {
          try {
            logService.log(LogService.LOG_INFO, "ping");
          } catch (RuntimeException re) {
            alternativeLog("error in LogService " + re);
          }
        } else {
          alternativeLog("LogService has gone");
        }

        pauseTestThread();
      }
    }
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:21,代碼來源:Activator.java

示例3: run

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void run() {

      while (Thread.currentThread() == m_logTestThread) {

        // we use the saved bundle context and service reference to get the real instance
        LogService logService = (LogService) m_context.getService(m_logServiceRef);

        // if the dereferenced instance is null then we know the service has been removed
        if (logService != null) {
          logService.log(LogService.LOG_INFO, "ping");
        } else {
          alternativeLog("LogService has gone");
        }

        pauseTestThread();
      }
    }
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:18,代碼來源:Activator.java

示例4: run

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void run() {

      while (Thread.currentThread() == m_logTestThread) {

        // query the tracker to find the best matching service
        LogService logService = (LogService) m_logTracker.getService();

        // if the service instance is null then we know there is no LogService available
        if (logService != null) {
          try {
            logService.log(LogService.LOG_INFO, "ping");
          } catch (RuntimeException re) {
            alternativeLog("error in LogService " + re);
          }
        } else {
          alternativeLog("LogService has gone");
        }

        pauseTestThread();
      }
    }
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:22,代碼來源:Activator.java

示例5: log

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
protected void log ( final int level, final String message )
{
    final BundleContext context = this.context;
    if ( context == null )
    {
        return;
    }

    final ServiceReference<LogService> ref = context.getServiceReference ( LogService.class );
    if ( ref == null )
    {
        return;
    }

    final LogService service = context.getService ( ref );
    if ( service == null )
    {
        return;
    }

    try
    {
        service.log ( level, message );
    }
    finally
    {
        context.ungetService ( ref );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:30,代碼來源:Activator.java

示例6: match

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
static boolean match(Requirement requirement, Capability capability, LogService log) {
	// Namespace MUST match
	if (!requirement.getNamespace().equals(capability.getNamespace())) {
           return false;
       }

	// If capability effective!=resolve then it matches only requirements with same effective
	String capabilityEffective = capability.getDirectives().get(Namespace.CAPABILITY_EFFECTIVE_DIRECTIVE);
	if (capabilityEffective != null) {
		String requirementEffective = requirement.getDirectives().get(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
		if (!capabilityEffective.equals(Namespace.EFFECTIVE_RESOLVE) && !capabilityEffective.equals(requirementEffective)) {
               return false;
           }
	}

	String filterStr = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
       if (filterStr == null) {
           return true; // no filter, the requirement always matches
       }

	try {
		Filter filter = FrameworkUtil.createFilter(filterStr);
		return filter.matches(capability.getAttributes());
	} catch (InvalidSyntaxException e) {
		if (log != null) {
			Resource resource = requirement.getResource();
			String id = resource != null ? getIdentity(resource) : "<unknown>";
			log.log(LogService.LOG_ERROR, String.format("Invalid filter syntax in requirement from resource %s: %s", id, filterStr), e);
		}
		return false;
	}
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:33,代碼來源:PluginResolveContext.java

示例7: warn

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
protected void warn(String message, Throwable t) {
    ServiceReference<LogService> ref = bundleContext.getServiceReference(LogService.class);
    if (ref != null) {
        LogService svc = bundleContext.getService(ref);
        svc.log(LogService.LOG_WARNING, message, t);
        bundleContext.ungetService(ref);
    }
}
 
開發者ID:ops4j,項目名稱:org.ops4j.pax.transx,代碼行數:9,代碼來源:AbstractActivator.java

示例8: activate

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
@Activate
void activate(BundleContext bundleContext) {
	ServiceTracker logServiceTracker = new ServiceTracker(bundleContext, LogService.class.getName(), null);
	logServiceTracker.open();
	
	LogService logService = (LogService) logServiceTracker.getService();
	
	if(logService != null)
        logService.log(LogService.LOG_INFO, "[" + this.getClass().getName() + "] Testing the logServiceWritter!");

}
 
開發者ID:maldiny,項目名稱:OSGI-en-Castellano,代碼行數:12,代碼來源:LogServiceWritter.java

示例9: log

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void log(ServiceReference serviceRef, int level, String message, Throwable throwable) {
    for (LogService obj : services) {
        obj.log(serviceRef, level, message, throwable);
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:8,代碼來源:OsgiLogManager.java

示例10: run

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void run() {

      while (Thread.currentThread() == m_logTestThread) {

        // lookup the current "best" LogService each time, just before we need to use it
        ServiceReference logServiceRef = m_context.getServiceReference(LogService.class.getName());

        // if the service reference is null then we know there's no log service available
        if (logServiceRef != null) {
          try {

            LogService logService = (LogService) m_context.getService(logServiceRef);

            // if the dereferenced instance is null then we know the service has been removed
            if (logService != null) {
              logService.log(LogService.LOG_INFO, "ping");
            } else {
              alternativeLog("LogService has gone");
            }

          } catch (RuntimeException re) {

            // any problems that occur when using or accessing the service are now reported
            alternativeLog("error in LogService " + re);

          } finally {

            // we should also remember to unget a service when we're done with it for a while
            m_context.ungetService(logServiceRef);

          }
        } else {
          alternativeLog("LogService has gone");
        }

        pauseTestThread();
      }
    }
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:39,代碼來源:Activator.java

示例11: log

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void log(int i, java.lang.String s) {
    LogService service = getLogService();
    if(service != null){
        service.log(i, s);
        //return;
    }
    print(i, s);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:9,代碼來源:Logger.java

示例12: internalLog

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
/**
 * Check the availability of the OSGI logging service, and use it is
 * available. Does nothing otherwise.
 *
 * @param level
 * @param message
 * @param t
 */
private void internalLog(int level, Object message, Throwable t) {
    LogService logservice = OSGILogFactory.getLogService();
    ServiceReference serviceref = OSGILogFactory.getServiceReference();

    StackTraceElement callerInfo = null;
    if (detailed) {
        callerInfo = Thread.currentThread().getStackTrace()[2];
    }
    if (logservice != null) {
        try {
            if (t != null) {
                logservice.log(serviceref, level, createMessagePart(level, callerInfo, message + ""), t);
            } else {
                logservice.log(serviceref, level, createMessagePart(level, callerInfo, message + ""));
            }
        } catch (Exception exc) {
            // Service may have become invalid, just ignore any error
            // until the log service reference is updated by the
            // log factory.
        }
    } else {
        BundleContext bundleContext = OSGILogFactory.getContext();
        Bundle bundle;
        try {
            bundle = bundleContext.getBundle();
        } catch (Throwable t1) {
            bundle = null;
        }

        System.out.println(
                new Date() + " " + getLogLevelString(level)
                + (bundle != null ? "  #" + bundle.getBundleId() + " " : "")
                + (bundle != null ? bundle.getSymbolicName() + " " : " ")
                + createMessagePart(level, callerInfo, message + ""));
        if (t != null) {
            t.printStackTrace();
        }
    }
}
 
開發者ID:Ericsson-LMF,項目名稱:IoT-Gateway,代碼行數:48,代碼來源:OSGiLogger.java

示例13: testLogClientBehaviour

import org.osgi.service.log.LogService; //導入方法依賴的package包/類
public void testLogClientBehaviour()
    throws Exception {

  // MOCK - create prototype mock objects
  // ====================================

  // we want a strict mock context so we can test the ordering
  BundleContext context = createStrictMock(BundleContext.class);
  ServiceReference serviceRef = createMock(ServiceReference.class);
  LogService logService = createMock(LogService.class);

  // nice mocks return reasonable defaults
  Bundle bundle = createNiceMock(Bundle.class);

  // EXPECT - script the expected behavior
  // =====================================

  // expected behaviour when log service is available
  expect(context.getServiceReference(LogService.class.getName()))
      .andReturn(serviceRef);
  expect(context.getService(serviceRef))
      .andReturn(logService);
  logService.log(
      and(geq(LogService.LOG_ERROR), leq(LogService.LOG_DEBUG)),
      isA(String.class));

  // expected behaviour when log service is not available
  expect(context.getServiceReference(LogService.class.getName()))
      .andReturn(null);
  expect(context.getBundle())
      .andReturn(bundle).anyTimes();

  // race condition: log service is available but immediately goes away
  expect(context.getServiceReference(LogService.class.getName()))
      .andReturn(serviceRef);
  expect(context.getService(serviceRef))
      .andReturn(null);
  expect(context.getBundle())
      .andReturn(bundle).anyTimes();

  // REPLAY - prepare the mock objects
  // =================================

  replay(context, serviceRef, logService, bundle);

  // TEST - run code using the mock objects
  // ======================================
  
  // this latch limits the calls to the log service
  final CountDownLatch latch = new CountDownLatch(3);

  // override pause method to allow test synchronization
  BundleActivator logClientActivator = new Activator() {
    @Override protected void pauseTestThread() {

      // report log call
      latch.countDown();

      // nothing else left to do?
      if (latch.getCount() == 0) {
        LockSupport.park();
      }
    }
  };

  logClientActivator.start(context);

  // timeout in case test deadlocks
  if (!latch.await(5, TimeUnit.SECONDS)) {
    fail("Still expecting" + latch.getCount() + " calls");
  }

  logClientActivator.stop(context);

  // VERIFY - check the behavior matches
  // ===================================

  verify(context, serviceRef, logService);
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:80,代碼來源:LogClientTests.java


注:本文中的org.osgi.service.log.LogService.log方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。