okhttp: use FINE log for pure IOExceptions

This commit is contained in:
Jihun Cho 2019-10-24 14:06:25 -07:00
parent c166ec2c4e
commit 30f8f26f7a
2 changed files with 10 additions and 16 deletions

View File

@ -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<String> 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;

View File

@ -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);
}