From 30f8f26f7a151f576f3b4f52b4571d99b2e65bee Mon Sep 17 00:00:00 2001 From: Jihun Cho Date: Thu, 24 Oct 2019 14:06:25 -0700 Subject: [PATCH] okhttp: use FINE log for pure IOExceptions --- .../grpc/okhttp/ExceptionHandlingFrameWriter.java | 12 +----------- .../okhttp/ExceptionHandlingFrameWriterTest.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/okhttp/src/main/java/io/grpc/okhttp/ExceptionHandlingFrameWriter.java b/okhttp/src/main/java/io/grpc/okhttp/ExceptionHandlingFrameWriter.java index 93a4c740e8..9f7074121f 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/ExceptionHandlingFrameWriter.java +++ b/okhttp/src/main/java/io/grpc/okhttp/ExceptionHandlingFrameWriter.java @@ -25,11 +25,7 @@ import io.grpc.okhttp.internal.framed.FrameWriter; import io.grpc.okhttp.internal.framed.Header; import io.grpc.okhttp.internal.framed.Settings; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import okio.Buffer; @@ -39,10 +35,6 @@ final class ExceptionHandlingFrameWriter implements FrameWriter { private static final Logger log = Logger.getLogger(OkHttpClientTransport.class.getName()); - // Some exceptions are not very useful and add too much noise to the log - private static final Set QUIET_ERRORS = - Collections.unmodifiableSet(new HashSet<>(Arrays.asList("Socket closed"))); - private final TransportExceptionHandler transportExceptionHandler; private final FrameWriter frameWriter; @@ -231,9 +223,7 @@ final class ExceptionHandlingFrameWriter implements FrameWriter { */ @VisibleForTesting static Level getLogLevel(Throwable t) { - if (t instanceof IOException - && t.getMessage() != null - && QUIET_ERRORS.contains(t.getMessage())) { + if (t.getClass().equals(IOException.class)) { return Level.FINE; } return Level.INFO; diff --git a/okhttp/src/test/java/io/grpc/okhttp/ExceptionHandlingFrameWriterTest.java b/okhttp/src/test/java/io/grpc/okhttp/ExceptionHandlingFrameWriterTest.java index 27e3c0fc3f..c26edcd0df 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/ExceptionHandlingFrameWriterTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/ExceptionHandlingFrameWriterTest.java @@ -71,18 +71,22 @@ public class ExceptionHandlingFrameWriterTest { } @Test - public void quiet() { + public void ioException() { assertThat(getLogLevel(new IOException("Socket closed"))).isEqualTo(Level.FINE); } @Test - public void nonquiet() { - assertThat(getLogLevel(new IOException("foo"))).isEqualTo(Level.INFO); + public void ioException_nullMessage() { + IOException e = new IOException(); + assertThat(e.getMessage()).isNull(); + assertThat(getLogLevel(e)).isEqualTo(Level.FINE); } @Test - public void nullMessage() { - IOException e = new IOException(); + public void extendedIoException() { + class ExtendedIoException extends IOException {} + + ExtendedIoException e = new ExtendedIoException(); assertThat(e.getMessage()).isNull(); assertThat(getLogLevel(e)).isEqualTo(Level.INFO); }