Skip to content

Commit

Permalink
Merge pull request square#1107 from square/jwilson_1026_one_logger
Browse files Browse the repository at this point in the history
Use one logger for all logging.
  • Loading branch information
JakeWharton committed Oct 26, 2014
2 parents 125df55 + 40c2e6a commit c079c9e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;
Expand All @@ -62,6 +61,7 @@
import org.junit.Ignore;
import org.junit.Test;

import static com.squareup.okhttp.internal.Internal.logger;
import static java.lang.Thread.UncaughtExceptionHandler;
import static java.net.CookiePolicy.ACCEPT_ORIGINAL_SERVER;
import static org.junit.Assert.assertEquals;
Expand All @@ -87,15 +87,15 @@ public final class CallTest {
File cacheDir = new File(tmp, "HttpCache-" + UUID.randomUUID());
cache = new Cache(cacheDir, Integer.MAX_VALUE);
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Logger.getLogger(OkHttpClient.class.getName()).addHandler(logHandler);
logger.addHandler(logHandler);
}

@After public void tearDown() throws Exception {
server.shutdown();
server2.shutdown();
cache.delete();
Thread.setDefaultUncaughtExceptionHandler(defaultUncaughtExceptionHandler);
Logger.getLogger(OkHttpClient.class.getName()).removeHandler(logHandler);
logger.removeHandler(logHandler);
}

@Test public void get() throws Exception {
Expand Down
5 changes: 2 additions & 3 deletions okhttp/src/main/java/com/squareup/okhttp/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.net.ProtocolException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import okio.BufferedSink;
import okio.BufferedSource;

import static com.squareup.okhttp.internal.Internal.logger;
import static com.squareup.okhttp.internal.http.HttpEngine.MAX_REDIRECTS;

/**
Expand Down Expand Up @@ -169,8 +169,7 @@ Call get() {
} catch (IOException e) {
if (signalledCallback) {
// Do not signal the callback twice!
Logger.getLogger(OkHttpClient.class.getName())
.log(Level.INFO, "Callback failure for " + toLoggableString(), e);
logger.log(Level.INFO, "Callback failure for " + toLoggableString(), e);
} else {
responseCallback.onFailure(request, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import com.squareup.okhttp.internal.http.HttpEngine;
import com.squareup.okhttp.internal.http.Transport;
import java.io.IOException;
import java.util.logging.Logger;

/**
* Escalate internal APIs in {@code com.squareup.okhttp} so they can be used
* from OkHttp's implementation packages. The only implementation of this
* interface is in {@link com.squareup.okhttp.OkHttpClient}.
*/
public abstract class Internal {
public static final Logger logger = Logger.getLogger(OkHttpClient.class.getName());
public static Internal instance;

public abstract Transport newTransport(Connection connection, HttpEngine httpEngine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.squareup.okhttp.internal;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Protocol;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
Expand All @@ -32,10 +31,11 @@
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLSocket;
import okio.Buffer;

import static com.squareup.okhttp.internal.Internal.logger;

/**
* Access to Platform-specific features necessary for SPDY and advanced TLS.
* This includes Server Name Indication (SNI) and session tickets.
Expand Down Expand Up @@ -328,9 +328,8 @@ public JdkWithJettyBootPlatform(Method putMethod, Method getMethod,
JettyNegoProvider provider =
(JettyNegoProvider) Proxy.getInvocationHandler(getMethod.invoke(null, socket));
if (!provider.unsupported && provider.selected == null) {
Logger.getLogger(OkHttpClient.class.getName()).log(Level.INFO,
"NPN/ALPN callback dropped: SPDY and HTTP/2 are disabled. "
+ "Is npn-boot or alpn-boot on the boot class path?");
logger.log(Level.INFO, "NPN/ALPN callback dropped: SPDY and HTTP/2 are disabled. "
+ "Is npn-boot or alpn-boot on the boot class path?");
return null;
}
return provider.unsupported ? null : provider.selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import com.squareup.okhttp.Protocol;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.ByteString;
import okio.Source;
import okio.Timeout;

import static com.squareup.okhttp.internal.Internal.logger;
import static com.squareup.okhttp.internal.spdy.Http20Draft14.FrameLogger.formatHeader;
import static java.lang.String.format;
import static java.util.logging.Level.FINE;
Expand All @@ -40,8 +40,6 @@
* <p>http://tools.ietf.org/html/draft-ietf-httpbis-http2-14
*/
public final class Http20Draft14 implements Variant {
private static final Logger logger = Logger.getLogger(Http20Draft14.class.getName());

@Override public Protocol getProtocol() {
return Protocol.HTTP_2;
}
Expand Down

0 comments on commit c079c9e

Please sign in to comment.