Sfoglia il codice sorgente

http2: quiet Transport logging

Add logf/vlogf helpers for Transport like the server side.

Change-Id: I9c9e5dc38c06118204da615c59de60cd3f9561ef
Reviewed-on: https://go-review.googlesource.com/16064
Reviewed-by: Andrew Gerrand <adg@golang.org>
Brad Fitzpatrick 10 anni fa
parent
commit
9946ad7d5e
1 ha cambiato i file con 31 aggiunte e 10 eliminazioni
  1. 31 10
      http2/transport.go

+ 31 - 10
http2/transport.go

@@ -256,7 +256,7 @@ func (t *Transport) newClientConn(host, port, key string) (*clientConn, error) {
 			cc.initialWindowSize = s.Val
 			cc.initialWindowSize = s.Val
 		default:
 		default:
 			// TODO(bradfitz): handle more
 			// TODO(bradfitz): handle more
-			log.Printf("Unhandled Setting: %v", s)
+			t.vlogf("Unhandled Setting: %v", s)
 		}
 		}
 		return nil
 		return nil
 	})
 	})
@@ -383,7 +383,6 @@ func (cc *clientConn) encodeHeaders(req *http.Request) []byte {
 }
 }
 
 
 func (cc *clientConn) writeHeader(name, value string) {
 func (cc *clientConn) writeHeader(name, value string) {
-	log.Printf("sending %q = %q", name, value)
 	cc.henc.WriteField(hpack.HeaderField{Name: name, Value: value})
 	cc.henc.WriteField(hpack.HeaderField{Name: name, Value: value})
 }
 }
 
 
@@ -442,21 +441,21 @@ func (cc *clientConn) readLoop() {
 			cc.readerErr = err
 			cc.readerErr = err
 			return
 			return
 		}
 		}
-		log.Printf("Transport received %v: %#v", f.Header(), f)
+		cc.vlogf("Transport received %v: %#v", f.Header(), f)
 
 
 		streamID := f.Header().StreamID
 		streamID := f.Header().StreamID
 
 
 		_, isContinue := f.(*ContinuationFrame)
 		_, isContinue := f.(*ContinuationFrame)
 		if isContinue {
 		if isContinue {
 			if streamID != continueStreamID {
 			if streamID != continueStreamID {
-				log.Printf("Protocol violation: got CONTINUATION with id %d; want %d", streamID, continueStreamID)
+				cc.logf("Protocol violation: got CONTINUATION with id %d; want %d", streamID, continueStreamID)
 				cc.readerErr = ConnectionError(ErrCodeProtocol)
 				cc.readerErr = ConnectionError(ErrCodeProtocol)
 				return
 				return
 			}
 			}
 		} else if continueStreamID != 0 {
 		} else if continueStreamID != 0 {
 			// Continue frames need to be adjacent in the stream
 			// Continue frames need to be adjacent in the stream
 			// and we were in the middle of headers.
 			// and we were in the middle of headers.
-			log.Printf("Protocol violation: got %T for stream %d, want CONTINUATION for %d", f, streamID, continueStreamID)
+			cc.logf("Protocol violation: got %T for stream %d, want CONTINUATION for %d", f, streamID, continueStreamID)
 			cc.readerErr = ConnectionError(ErrCodeProtocol)
 			cc.readerErr = ConnectionError(ErrCodeProtocol)
 			return
 			return
 		}
 		}
@@ -473,7 +472,7 @@ func (cc *clientConn) readLoop() {
 
 
 		cs := cc.streamByID(streamID, streamEnded)
 		cs := cc.streamByID(streamID, streamEnded)
 		if cs == nil {
 		if cs == nil {
-			log.Printf("Received frame for untracked stream ID %d", streamID)
+			cc.logf("Received frame for untracked stream ID %d", streamID)
 			continue
 			continue
 		}
 		}
 
 
@@ -489,17 +488,19 @@ func (cc *clientConn) readLoop() {
 		case *ContinuationFrame:
 		case *ContinuationFrame:
 			cc.hdec.Write(f.HeaderBlockFragment())
 			cc.hdec.Write(f.HeaderBlockFragment())
 		case *DataFrame:
 		case *DataFrame:
-			log.Printf("DATA: %q", f.Data())
+			if VerboseLogs {
+				cc.logf("DATA: %q", f.Data())
+			}
 			cs.pw.Write(f.Data())
 			cs.pw.Write(f.Data())
 		case *GoAwayFrame:
 		case *GoAwayFrame:
 			cc.t.removeClientConn(cc)
 			cc.t.removeClientConn(cc)
 			if f.ErrCode != 0 {
 			if f.ErrCode != 0 {
 				// TODO: deal with GOAWAY more. particularly the error code
 				// TODO: deal with GOAWAY more. particularly the error code
-				log.Printf("transport got GOAWAY with error code = %v", f.ErrCode)
+				cc.vlogf("transport got GOAWAY with error code = %v", f.ErrCode)
 			}
 			}
 			cc.setGoAway(f)
 			cc.setGoAway(f)
 		default:
 		default:
-			log.Printf("Transport: unhandled response frame type %T", f)
+			cc.logf("Transport: unhandled response frame type %T", f)
 		}
 		}
 		headersEnded := false
 		headersEnded := false
 		if he, ok := f.(headersEnder); ok {
 		if he, ok := f.(headersEnder); ok {
@@ -533,7 +534,9 @@ func (cc *clientConn) readLoop() {
 func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
 func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
 	// TODO: verifiy pseudo headers come before non-pseudo headers
 	// TODO: verifiy pseudo headers come before non-pseudo headers
 	// TODO: verifiy the status is set
 	// TODO: verifiy the status is set
-	log.Printf("Header field: %+v", f)
+	if VerboseLogs {
+		cc.logf("Header field: %+v", f)
+	}
 	if f.Name == ":status" {
 	if f.Name == ":status" {
 		code, err := strconv.Atoi(f.Value)
 		code, err := strconv.Atoi(f.Value)
 		if err != nil {
 		if err != nil {
@@ -550,3 +553,21 @@ func (cc *clientConn) onNewHeaderField(f hpack.HeaderField) {
 	}
 	}
 	cc.nextRes.Header.Add(http.CanonicalHeaderKey(f.Name), f.Value)
 	cc.nextRes.Header.Add(http.CanonicalHeaderKey(f.Name), f.Value)
 }
 }
+
+func (cc *clientConn) logf(format string, args ...interface{}) {
+	cc.t.logf(format, args...)
+}
+
+func (cc *clientConn) vlogf(format string, args ...interface{}) {
+	cc.t.vlogf(format, args...)
+}
+
+func (t *Transport) vlogf(format string, args ...interface{}) {
+	if VerboseLogs {
+		t.logf(format, args...)
+	}
+}
+
+func (t *Transport) logf(format string, args ...interface{}) {
+	log.Printf(format, args...)
+}