Menu

Usage Example

Manfred Wong

It's very easy to use, just like the way you use the original LogService.

Step1: import

import com.atlanssia.osgi.logservice.LogServiceExt;

Step2: Get the extended service from context in your bundle, and start use:

    ServiceReference ref = context.getServiceReference(LogServiceExt.class.getName());
        LogServiceExt log = null;
        if (ref != null)
        {
             log = (LogServiceExt) context.getService(ref);

            log.log(LogService.LOG_INFO, "Logged:hello atlanssia!");

            log.error("Log a exception", new Exception("Im a exception from Atlanssia"));
        }

Step3: Make sure the bundle logservice-x.x.x-SNAPSHOT.jar started before this bundle.

After all, take a look at the log file, it looks as below(with logback):

2012-12-05 00:47:36,116 INFO  [FelixStartLevel]com.atlanssia.substruction.kernel.Activator.start(Activator.java:49)-Logged:hello atlanssia!
2012-12-05 00:47:36,121 ERROR [FelixStartLevel]com.atlanssia.substruction.kernel.Activator.start(Activator.java:51)-Log a exception
java.lang.Exception: Im a exception from Atlanssia
    at com.atlanssia.substruction.kernel.Activator.start(Activator.java:51) ~[classes/:na]
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645) ~[felix.jar:na]
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977) ~[felix.jar:na]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1895) ~[felix.jar:na]
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191) ~[felix.jar:na]
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295) ~[felix.jar:na]
    at java.lang.Thread.run(Thread.java:722) ~[na:1.7.0_04]

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.