Skip to content

Commit

Permalink
Fixed logging on Guice user to identify the exception as normal and t…
Browse files Browse the repository at this point in the history
…o put them in the log file.
  • Loading branch information
ieb committed Apr 2, 2009
1 parent d915170 commit a8ba899
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
26 changes: 14 additions & 12 deletions slingtests/osgikernel/bundles/guiceuser/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements. See the NOTICE file distributed with this work for additional information regarding
copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
Expand All @@ -9,7 +9,8 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
the License for the specific language governing permissions and limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sakaiproject.kernel2.osgi</groupId>
Expand All @@ -34,10 +35,7 @@
<instructions>
<Bundle-Category> sakai-kernel </Bundle-Category>
<Bundle-Activator>org.sakaiproject.kernel2.osgi.guiceuser.GuiceUser</Bundle-Activator>
<Import-Package>
com.google.inject.cglib.reflect,
*
</Import-Package>
<Import-Package> com.google.inject.cglib.reflect, * </Import-Package>
</instructions>
</configuration>
</plugin>
Expand All @@ -53,12 +51,16 @@
<groupId>com.google.code.guice</groupId>
<artifactId>guice</artifactId>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@
import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceF;
import org.sakaiproject.kernel2.osgi.guiceuser.impl.FProvider;
import org.sakaiproject.kernel2.osgi.guiceuser.impl.InjectableC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GuiceUser implements BundleActivator {

private static final Logger LOGGER = LoggerFactory.getLogger(GuiceUser.class);

public void start(BundleContext arg0) throws Exception {
System.out.println("Fetching injector");
LOGGER.info("Fetching injector");
Injector injector = Guice.createInjector(new TestModule());
System.err.println("Fetching Injectable instance");
LOGGER.info("Fetching Injectable instance");
injector.getInstance(InjectableC.class);
System.err.println("Print test 1");
LOGGER.info("Print test 1");
InterfaceD d = injector.getInstance(InterfaceD.class);
d.printHello();
InterfaceE e = injector.getInstance(InterfaceE.class);
System.err.println("Print test 2");
LOGGER.info("Print test 2");
e.printHelloViaD();
Provider<InterfaceF> fprovider = injector.getInstance(FProvider.class);
System.err.println("Print test 3");
LOGGER.info("Print test 3");
fprovider.get().printViaE();
}

public void stop(BundleContext arg0) throws Exception {
System.out.println("Stopping");
LOGGER.info("Stopping");
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.sakaiproject.kernel2.osgi.guiceuser.impl;

import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConcreteB implements InterfaceB {

private static final Logger LOGGER = LoggerFactory.getLogger(ConcreteB.class);

public void printString(String string) {
new Exception().printStackTrace();
System.out.println(string);
Exception e = new Exception("Traceback, not an exception");
LOGGER.info(string,e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceB;
import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceD;
import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConcreteE implements InterfaceE {

private static final Logger LOGGER = LoggerFactory.getLogger(ConcreteE.class);
private InterfaceD d;

@Inject
Expand All @@ -24,7 +27,7 @@ public void printHelloViaD()

public void doPrint(InterfaceA a, InterfaceB b)
{
System.err.println("Printing from e");
LOGGER.info("Printing from e");
b.printString(a.getHelloWorld());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceE;
import org.sakaiproject.kernel2.osgi.guiceuser.api.InterfaceF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FProvider implements Provider<InterfaceF> {

protected static final Logger LOGGER = LoggerFactory.getLogger(FProvider.class);
private InterfaceE e;

@Inject
Expand All @@ -21,7 +24,7 @@ public InterfaceF get() {
{

public void printViaE() {
System.err.println("Provided F printing via e via d");
LOGGER.info("Provided F printing via e via d");
FProvider.this.getE().printHelloViaD();
}
};
Expand Down

0 comments on commit a8ba899

Please sign in to comment.