Skip to content

Commit

Permalink
Adjust logging for Jersey to use SLF4J
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f authored and Andrew Woods committed Oct 17, 2014
1 parent daf10ec commit 58bdaa2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
17 changes: 11 additions & 6 deletions fcrepo-http-api/pom.xml
Expand Up @@ -72,12 +72,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<scope>test</scope>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
Expand Down Expand Up @@ -118,10 +112,21 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<scope>test</scope>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Expand Up @@ -30,8 +30,6 @@
import java.io.UnsupportedEncodingException;
import java.util.UUID;

import com.hp.hpl.jena.update.GraphStore;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
Expand All @@ -43,18 +41,18 @@
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Before;
Expand All @@ -63,6 +61,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.hp.hpl.jena.update.GraphStore;

/**
* <p>Abstract AbstractResourceIT class.</p>
*
Expand Down
3 changes: 3 additions & 0 deletions fcrepo-http-api/src/test/resources/logback-test.xml
Expand Up @@ -19,6 +19,9 @@
<logger name="com.gargoylesoftware.htmlunit" additivity="false" level="ERROR">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.glassfish" additivity="false" level="ERROR">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="WARN">
<appender-ref ref="STDOUT"/>
</root>
Expand Down
5 changes: 4 additions & 1 deletion fcrepo-http-commons/pom.xml
Expand Up @@ -108,7 +108,10 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-configs</artifactId>
Expand Down
Expand Up @@ -20,6 +20,7 @@
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.rdf.model.Resource;

import org.fcrepo.http.commons.session.SessionFactory;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
Expand All @@ -30,6 +31,7 @@
import org.fcrepo.kernel.services.RepositoryService;
import org.fcrepo.kernel.services.VersionService;
import org.jvnet.hk2.annotations.Optional;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.eventbus.EventBus;
Expand All @@ -42,6 +44,13 @@
*/
public abstract class AbstractResource {

static {
// the SLF4J to JUL bridge normally adds its attachments
// we want them to _replace_ the JUL loggers, to avoid logging outputs except those controlled by SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}

/**
* Useful for constructing URLs
*/
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -443,6 +443,11 @@
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down

0 comments on commit 58bdaa2

Please sign in to comment.