Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-26 09:45:04 -0400
committerChristopher Frost2011-05-26 09:45:04 -0400
commitd8c8035f1294797471842a9ba20de6d5cacb23b5 (patch)
tree0a66c57e89d58c9f246f9c051e6dbd4bf71d443e
parent8f590ac6e3b6684fecf5ef082125a0dbfea06545 (diff)
downloadorg.eclipse.virgo.medic-d8c8035f1294797471842a9ba20de6d5cacb23b5.tar.gz
org.eclipse.virgo.medic-d8c8035f1294797471842a9ba20de6d5cacb23b5.tar.xz
org.eclipse.virgo.medic-d8c8035f1294797471842a9ba20de6d5cacb23b5.zip
342716 Adding support for the OSGi LogService that backs on to the Medic system
-rw-r--r--org.eclipse.virgo.medic.core/.classpath2
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java10
-rw-r--r--org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java104
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java284
4 files changed, 395 insertions, 5 deletions
diff --git a/org.eclipse.virgo.medic.core/.classpath b/org.eclipse.virgo.medic.core/.classpath
index 138b6bf..bb1e35e 100644
--- a/org.eclipse.virgo.medic.core/.classpath
+++ b/org.eclipse.virgo.medic.core/.classpath
@@ -33,6 +33,6 @@
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.0.0.M04/org.eclipse.virgo.util.osgi-3.0.0.M04.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.0.0.M04/org.eclipse.virgo.util.osgi-sources-3.0.0.M04.jar"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.cm/1.0.300.v20101204/org.eclipse.equinox.cm-1.0.300.v20101204.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.cm/1.0.300.v20101204/org.eclipse.equinox.cm-sources-1.0.300.v20101204.jar"/>
- <classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar"/>
+ <classpathentry kind="var" path="MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar" sourcepath="/MEDIC_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-sources-3.3.0.v20110110.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
index 3249227..acba2fb 100644
--- a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/impl/MedicActivator.java
@@ -22,6 +22,8 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceFactory;
import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.log.LogService;
+import org.slf4j.LoggerFactory;
import org.eclipse.virgo.medic.dump.DumpGenerator;
import org.eclipse.virgo.medic.dump.impl.DumpContributorPublisher;
@@ -56,9 +58,9 @@ import org.eclipse.virgo.medic.log.impl.logback.DelegatingContextSelector;
import org.eclipse.virgo.medic.log.impl.logback.JoranLoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.LoggerContextConfigurer;
import org.eclipse.virgo.medic.log.impl.logback.StandardContextSelectorDelegate;
+import org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
-@SuppressWarnings("deprecation")
public final class MedicActivator implements BundleActivator {
private static final String LOGGER_NAME_SYSERR = "System.err";
@@ -98,11 +100,11 @@ public final class MedicActivator implements BundleActivator {
public void start(BundleContext context) throws Exception {
ConfigurationProvider configurationProvider = new ConfigurationAdminConfigurationProvider(context);
- this.registrationTracker.track(context.registerService(ConfigurationListener.class.getName(), configurationProvider, null));
-
+ this.registrationTracker.track(context.registerService(ConfigurationListener.class.getName(), configurationProvider, null));
logStart(context, configurationProvider);
eventLogStart(context);
dumpStart(context, configurationProvider);
+ this.registrationTracker.track(context.registerService(LogService.class.getName(), new OSGiLogServiceImpl(LoggerFactory.getLogger(LogService.class)), null));
}
public void stop(BundleContext context) throws Exception {
@@ -236,7 +238,7 @@ public final class MedicActivator implements BundleActivator {
return new SecurityManagerExecutionStackAccessor();
}
- private void logStop(@SuppressWarnings("unused") BundleContext context) {
+ private void logStop(BundleContext context) {
System.setProperty(PROPERTY_LOGBACK_CONTEXT_SELECTOR, DEFAULT_CONTEXT_SELECTOR);
diff --git a/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java
new file mode 100644
index 0000000..abb6d97
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/main/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImpl.java
@@ -0,0 +1,104 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 copyright_holder
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * cgfrost - initial contribution
+ */
+
+package org.eclipse.virgo.medic.log.osgi;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+
+
+/**
+ * TODO Document EquinoxLogServiceImpl
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * TODO Document concurrent semantics of EquinoxLogServiceImpl
+ */
+public class OSGiLogServiceImpl implements LogService {
+
+ private final Logger logger;
+
+ public OSGiLogServiceImpl(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void log(int level, String message) {
+ switch (level) {
+ case LogService.LOG_DEBUG :
+ this.logger.debug(message);
+ break;
+ case LogService.LOG_INFO :
+ this.logger.info(message);
+ break;
+ case LogService.LOG_WARNING :
+ this.logger.warn(message);
+ break;
+ case LogService.LOG_ERROR :
+ this.logger.error(message);
+ break;
+ default :
+ this.logger.error(String.format("Log Message of unknown severity %d: %s", level, message));
+ break;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void log(int level, String message, Throwable exception) {
+ switch (level) {
+ case LogService.LOG_DEBUG :
+ this.logger.debug(message, exception);
+ break;
+ case LogService.LOG_INFO :
+ this.logger.info(message, exception);
+ break;
+ case LogService.LOG_WARNING :
+ this.logger.warn(message, exception);
+ break;
+ case LogService.LOG_ERROR :
+ this.logger.error(message, exception);
+ break;
+ default :
+ this.logger.error(String.format("Log Message of unknown severity %d: %s", level, message), exception);
+ break;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void log(ServiceReference sr, int level, String message) {
+ this.log(level, String.format("{Service %s}: %s", getServiceDescription(sr), message));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void log(ServiceReference sr, int level, String message, Throwable exception) {
+ this.log(level, String.format("{Service %s}: %s", getServiceDescription(sr), message), exception);
+ }
+
+ private String getServiceDescription(ServiceReference<?> sr){
+ return sr.getProperty("service.id").toString();
+ }
+
+}
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java
new file mode 100644
index 0000000..a80cc8f
--- /dev/null
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/log/osgi/OSGiLogServiceImplTests.java
@@ -0,0 +1,284 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 copyright_holder
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * cgfrost - initial contribution
+ */
+
+package org.eclipse.virgo.medic.log.osgi;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.framework.StubServiceReference;
+import org.eclipse.virgo.teststubs.osgi.framework.StubServiceRegistration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ *
+ * OSGiLogServiceImplTests
+ */
+public class OSGiLogServiceImplTests {
+
+ private static final String TEST_MESSAGE = "Danger Will Robinson, Danger!!!";
+
+ private static final ServiceReference<Object> SERVICE_REF = new StubServiceReference<Object>(3l, 3, new StubServiceRegistration<Object>(new StubBundleContext(), "org.eclipse.virgo.not.here"));
+
+ private static final String SERVICE_PREFIX = "{Service 3}: ";
+
+ private static final String INVALID_PREFIX = "Log Message of unknown severity 99: ";
+
+ private static final Throwable FAIL = new Throwable("Got lost in space");
+
+ private OSGiLogServiceImpl osgiLogService;
+
+ private Logger logService;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ this.logService = createMock(Logger.class);
+ this.osgiLogService = new OSGiLogServiceImpl(this.logService);
+ }
+
+ @After
+ public void setDown() {
+ verify(this.logService);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
+ */
+ @Test
+ public void testDebugLog() {
+ this.logService.debug(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_DEBUG, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testDebugLogThrowable() {
+ this.logService.debug(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_DEBUG, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
+ */
+ @Test
+ public void testDebugLogServiceReference() {
+ this.logService.debug(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_DEBUG, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testDebugLogServiceReferenceThrowable() {
+ this.logService.debug(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_DEBUG, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
+ */
+ @Test
+ public void testInfoLog() {
+ this.logService.info(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_INFO, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testInfoLogThrowable() {
+ this.logService.info(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_INFO, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
+ */
+ @Test
+ public void testInfoLogServiceReference() {
+ this.logService.info(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_INFO, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testInfoLogServiceReferenceThrowable() {
+ this.logService.info(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_INFO, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
+ */
+ @Test
+ public void testWarningLog() {
+ this.logService.warn(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_WARNING, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testWarningLogThrowable() {
+ this.logService.warn(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_WARNING, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
+ */
+ @Test
+ public void testWarningLogServiceReference() {
+ this.logService.warn(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_WARNING, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testWarningLogServiceReferenceThrowable() {
+ this.logService.warn(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_WARNING, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
+ */
+ @Test
+ public void testErrorLog() {
+ this.logService.error(TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_ERROR, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testErrorLogThrowable() {
+ this.logService.error(TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(LogService.LOG_ERROR, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
+ */
+ @Test
+ public void testErrorLogServiceReference() {
+ this.logService.error(SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_ERROR, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testErrorLogServiceReferenceThrowable() {
+ this.logService.error(SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, LogService.LOG_ERROR, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String)}.
+ */
+ @Test
+ public void testInvalidLog() {
+ this.logService.error(INVALID_PREFIX + TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(99, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testInvalidLogThrowable() {
+ this.logService.error(INVALID_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(99, TEST_MESSAGE, FAIL);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String)}.
+ */
+ @Test
+ public void testInvalidLogServiceReference() {
+ this.logService.error(INVALID_PREFIX + SERVICE_PREFIX +TEST_MESSAGE);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, 99, TEST_MESSAGE);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.medic.log.osgi.OSGiLogServiceImpl#log(org.osgi.framework.ServiceReference, int, java.lang.String, java.lang.Throwable)}.
+ */
+ @Test
+ public void testInvalidLogServiceReferenceThrowable() {
+ this.logService.error(INVALID_PREFIX + SERVICE_PREFIX + TEST_MESSAGE, FAIL);
+ expectLastCall().once();
+ replay(this.logService);
+ this.osgiLogService.log(SERVICE_REF, 99, TEST_MESSAGE, FAIL);
+ }
+
+}

Back to the top