Permalink
Browse files

Replace java.utils.logging with SLF4J

SLF4J grants the end-user the liberty to choose the underlying logging framework.
  • Loading branch information...
quiqua committed Dec 20, 2016
1 parent b65a972 commit d42f5d2d809b294a8ce78f90694963dd5e6163ba
@@ -11,4 +11,6 @@ dependencies {
compile commonDependencies.tika
compile commonDependencies.littleProxy
compile commonDependencies.netty
compile commonDependencies.log4jCore
compile commonDependencies.log4jSlf4jImpl
}
@@ -18,8 +18,8 @@
import org.apache.tika.mime.MimeTypeException;
import org.apache.tika.mime.MimeTypes;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Maps _MIME_ types to file extensions.
@@ -34,7 +34,7 @@
private static final MimeTypes MIME_TYPES = MimeTypes.getDefaultMimeTypes();
private static final Logger LOG = Logger.getLogger(FileTypeMapper.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(FileTypeMapper.class.getName());
/**
* Returns a filename consisting of `baseName` and an appropriate file
@@ -50,7 +50,7 @@ public static String filenameFor(String baseName, String contentType) {
String extension = MIME_TYPES.forName(contentType).getExtension();
filename = baseName + extension;
} catch (MimeTypeException e) {
LOG.warning(String.format("Could not get extension for %s content type: %s", contentType, e.getMessage()));
LOG.warn(String.format("Could not get extension for %s content type: %s", contentType, e.getMessage()));
filename = baseName + DEFAULT_EXTENSION;
}
return filename;
@@ -22,6 +22,8 @@
import io.netty.handler.codec.http.*;
import org.littleshoot.proxy.HttpFiltersAdapter;
import org.littleshoot.proxy.impl.ProxyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.betamax.Headers;
import software.betamax.encoding.DeflateEncoder;
import software.betamax.encoding.GzipEncoder;
@@ -33,22 +35,20 @@
import java.io.IOException;
import java.util.Map;
import java.util.logging.Logger;
import static io.netty.buffer.Unpooled.wrappedBuffer;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_ENCODING;
import static io.netty.handler.codec.http.HttpHeaders.Names.VIA;
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static java.util.logging.Level.SEVERE;
public class BetamaxFilters extends HttpFiltersAdapter {
private NettyRequestAdapter request;
private NettyResponseAdapter upstreamResponse;
private final Tape tape;
private static final Logger LOG = Logger.getLogger(BetamaxFilters.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(BetamaxFilters.class.getName());
public BetamaxFilters(HttpRequest originalRequest, Tape tape) {
super(originalRequest);
@@ -103,7 +103,7 @@ public HttpObject serverToProxyResponse(HttpObject httpObject) {
upstreamResponse.append((HttpContent) httpObject);
} catch (IOException e) {
// TODO: handle in some way
LOG.log(SEVERE, "Error appending content", e);
LOG.error("Error appending content", e);
}
}
@@ -140,14 +140,14 @@ public HttpObject proxyToClientResponse(HttpObject httpObject) {
if (tape == null) {
return Optional.of(new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(403, "No tape")));
} else if (tape.isReadable() && tape.seek(request)) {
LOG.warning(String.format("Playing back from tape %s", tape.getName()));
LOG.warn(String.format("Playing back from tape %s", tape.getName()));
Response recordedResponse = tape.play(request);
FullHttpResponse response = playRecordedResponse(recordedResponse);
setViaHeader(response);
setBetamaxHeader(response, "PLAY");
return Optional.of(response);
} else {
LOG.warning(String.format("no matching request found on %s", tape.getName()));
LOG.warn(String.format("no matching request found on %s", tape.getName()));
return Optional.absent();
}
}
@@ -20,6 +20,8 @@
import io.netty.handler.codec.http.HttpRequest;
import org.littleshoot.proxy.*;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.betamax.Configuration;
import software.betamax.internal.RecorderListener;
import software.betamax.proxy.netty.PredicatedHttpFilters;
@@ -28,7 +30,6 @@
import software.betamax.util.ProxyOverrider;
import java.net.InetSocketAddress;
import java.util.logging.Logger;
import static com.google.common.base.Predicates.not;
import static io.netty.handler.codec.http.HttpMethod.CONNECT;
@@ -43,7 +44,7 @@
private static final Predicate<HttpRequest> NOT_CONNECT = not(httpMethodPredicate(CONNECT));
private static final Logger LOG = Logger.getLogger(ProxyServer.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(ProxyServer.class.getName());
public ProxyServer(Configuration configuration) {
this.configuration = configuration;
@@ -18,6 +18,8 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.io.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
@@ -33,7 +35,6 @@
import java.io.*;
import java.nio.charset.Charset;
import java.util.logging.Logger;
import static org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK;
@@ -43,7 +44,7 @@
private final FileResolver fileResolver;
private static final Logger LOG = Logger.getLogger(YamlTapeLoader.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(YamlTapeLoader.class.getName());
public YamlTapeLoader(File tapeRoot) {
fileResolver = new FileResolver(tapeRoot);
@@ -21,12 +21,11 @@
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.betamax.*;
import java.util.logging.Logger;
import static com.google.common.base.CaseFormat.*;
import static java.util.logging.Level.SEVERE;
/**
* This is an extension of {@link Recorder} that can be used as a
@@ -36,7 +35,7 @@
*/
public class RecorderRule extends Recorder implements TestRule {
private final Logger log = Logger.getLogger(RecorderRule.class.getName());
private final Logger log = LoggerFactory.getLogger(RecorderRule.class.getName());
public RecorderRule() {
super();
@@ -50,7 +49,7 @@ public RecorderRule(Configuration configuration) {
public Statement apply(final Statement statement, final Description description) {
final Betamax annotation = description.getAnnotation(Betamax.class);
if (annotation != null) {
log.fine(String.format("found @Betamax annotation on '%s'", description.getDisplayName()));
log.debug(String.format("found @Betamax annotation on '%s'", description.getDisplayName()));
return new Statement() {
@Override
public void evaluate() throws Throwable {
@@ -74,15 +73,15 @@ public void evaluate() throws Throwable {
statement.evaluate();
} catch (Exception e) {
log.log(SEVERE, "Caught exception starting Betamax", e);
log.error("Caught exception starting Betamax", e);
throw e;
} finally {
stop();
}
}
};
} else {
log.fine(String.format("no @Betamax annotation on '%s'", description.getDisplayName()));
log.debug(String.format("no @Betamax annotation on '%s'", description.getDisplayName()));
return statement;
}
}
@@ -26,4 +26,8 @@ dependencies {
testCompile "com.github.groovy-wslite:groovy-wslite:0.8.0"
testCompile "com.mashape.unirest:unirest-java:1.2.8", "org.apache.httpcomponents:httpasyncclient:4.0"
}
}
test {
testLogging.showStandardStreams = true
}
@@ -1,8 +0,0 @@
handlers = java.util.logging.ConsoleHandler
.level = ALL
java.util.logging.ConsoleHandler.level = WARN
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
betamax.level = ALL
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%p] [%t] %C{5} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="STDOUT"/>
</Root>
<Logger name="software.betamax" level="INFO" additivity="false">
<AppenderRef ref="STDOUT"/>
</Logger>
<Logger name="org.littleshoot" level="ERROR" additivity="false">
<AppenderRef ref="STDOUT"/>
</Logger>
</Loggers>
</Configuration>
View
@@ -7,23 +7,25 @@ allprojects {
isSnapshot = version.endsWith("-SNAPSHOT")
commonDependencies = [
cglib: dependencies.create("cglib:cglib-nodep:2.2.2"),
groovy: dependencies.create("org.codehaus.groovy:groovy-all:2.4.5:indy"),
guava: dependencies.create("com.google.guava:guava:18.0"),
httpBuilder: dependencies.create("org.codehaus.groovy.modules.http-builder:http-builder:0.6", {
exclude module: "groovy"
exclude module: "httpclient"
}),
httpClient: dependencies.create("org.apache.httpcomponents:httpclient:4.3.1"),
junit: dependencies.create("junit:junit:4.12"),
littleProxy: dependencies.create("org.littleshoot:littleproxy:1.1.0-beta2"),
netty: dependencies.create("io.netty:netty-all:4.0.35.Final"),
snakeYaml: dependencies.create("org.yaml:snakeyaml:1.16"),
spock: dependencies.create("org.spockframework:spock-core:1.0-groovy-2.4", {
exclude module: "groovy-all"
exclude module: "junit"
}),
tika: dependencies.create("org.apache.tika:tika-core:1.11")
cglib : dependencies.create("cglib:cglib-nodep:2.2.2"),
groovy : dependencies.create("org.codehaus.groovy:groovy-all:2.4.5:indy"),
guava : dependencies.create("com.google.guava:guava:18.0"),
httpBuilder : dependencies.create("org.codehaus.groovy.modules.http-builder:http-builder:0.6", {
exclude module: "groovy"
exclude module: "httpclient"
}),
httpClient : dependencies.create("org.apache.httpcomponents:httpclient:4.3.1"),
junit : dependencies.create("junit:junit:4.12"),
littleProxy : dependencies.create("org.littleshoot:littleproxy:1.1.0-beta2"),
log4jCore : dependencies.create("org.apache.logging.log4j:log4j-core:2.0.1"),
log4jSlf4jImpl: dependencies.create("org.apache.logging.log4j:log4j-slf4j-impl:2.0.1"),
netty : dependencies.create("io.netty:netty-all:4.0.35.Final"),
snakeYaml : dependencies.create("org.yaml:snakeyaml:1.16"),
spock : dependencies.create("org.spockframework:spock-core:1.0-groovy-2.4", {
exclude module: "groovy-all"
exclude module: "junit"
}),
tika : dependencies.create("org.apache.tika:tika-core:1.11")
]
}
}

0 comments on commit d42f5d2

Please sign in to comment.