diff --git a/benchmark/benchmark.go b/benchmark/benchmark.go index 273ca3b9..cda92a6d 100644 --- a/benchmark/benchmark.go +++ b/benchmark/benchmark.go @@ -38,7 +38,6 @@ package benchmark import ( "io" - "log" "math" "net" "time" @@ -46,20 +45,21 @@ import ( "github.com/golang/protobuf/proto" "golang.org/x/net/context" "google.golang.org/grpc" + "google.golang.org/grpc/grpclog" testpb "google.golang.org/grpc/interop/grpc_testing" ) func newPayload(t testpb.PayloadType, size int) *testpb.Payload { if size < 0 { - log.Fatalf("Requested a response with invalid length %d", size) + grpclog.Fatalf("Requested a response with invalid length %d", size) } body := make([]byte, size) switch t { case testpb.PayloadType_COMPRESSABLE: case testpb.PayloadType_UNCOMPRESSABLE: - log.Fatalf("PayloadType UNCOMPRESSABLE is not supported") + grpclog.Fatalf("PayloadType UNCOMPRESSABLE is not supported") default: - log.Fatalf("Unsupported payload type: %d", t) + grpclog.Fatalf("Unsupported payload type: %d", t) } return &testpb.Payload{ Type: t.Enum(), @@ -170,7 +170,7 @@ func (s *testServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServ func StartServer() (string, func()) { lis, err := net.Listen("tcp", ":0") if err != nil { - log.Fatalf("Failed to listen: %v", err) + grpclog.Fatalf("Failed to listen: %v", err) } s := grpc.NewServer(grpc.MaxConcurrentStreams(math.MaxUint32)) testpb.RegisterTestServiceServer(s, &testServer{}) @@ -189,7 +189,7 @@ func DoUnaryCall(tc testpb.TestServiceClient, reqSize, respSize int) { Payload: pl, } if _, err := tc.UnaryCall(context.Background(), req); err != nil { - log.Fatal("/TestService/UnaryCall RPC failed: ", err) + grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err) } } @@ -197,7 +197,7 @@ func DoUnaryCall(tc testpb.TestServiceClient, reqSize, respSize int) { func NewClientConn(addr string) *grpc.ClientConn { conn, err := grpc.Dial(addr) if err != nil { - log.Fatalf("NewClientConn(%q) failed to create a ClientConn %v", addr, err) + grpclog.Fatalf("NewClientConn(%q) failed to create a ClientConn %v", addr, err) } return conn } diff --git a/benchmark/client/main.go b/benchmark/client/main.go index 4bd87a0e..595d80ba 100644 --- a/benchmark/client/main.go +++ b/benchmark/client/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "log" "math" "net" "net/http" @@ -12,6 +11,7 @@ import ( "google.golang.org/grpc/benchmark" "google.golang.org/grpc/benchmark/stats" + "google.golang.org/grpc/grpclog" testpb "google.golang.org/grpc/interop/grpc_testing" ) @@ -70,7 +70,7 @@ func closeLoop() { close(ch) wg.Wait() conn.Close() - log.Println(s.String()) + grpclog.Println(s.String()) } func main() { @@ -78,11 +78,11 @@ func main() { go func() { lis, err := net.Listen("tcp", ":0") if err != nil { - log.Fatalf("Failed to listen: %v", err) + grpclog.Fatalf("Failed to listen: %v", err) } - log.Println("Client profiling address: ", lis.Addr().String()) + grpclog.Println("Client profiling address: ", lis.Addr().String()) if err := http.Serve(lis, nil); err != nil { - log.Fatalf("Failed to serve: %v", err) + grpclog.Fatalf("Failed to serve: %v", err) } }() closeLoop() diff --git a/benchmark/server/main.go b/benchmark/server/main.go index d24a4478..747f9f3b 100644 --- a/benchmark/server/main.go +++ b/benchmark/server/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "log" "math" "net" "net/http" @@ -10,6 +9,7 @@ import ( "time" "google.golang.org/grpc/benchmark" + "google.golang.org/grpc/grpclog" ) var ( @@ -21,15 +21,15 @@ func main() { go func() { lis, err := net.Listen("tcp", ":0") if err != nil { - log.Fatalf("Failed to listen: %v", err) + grpclog.Fatalf("Failed to listen: %v", err) } - log.Println("Server profiling address: ", lis.Addr().String()) + grpclog.Println("Server profiling address: ", lis.Addr().String()) if err := http.Serve(lis, nil); err != nil { - log.Fatalf("Failed to serve: %v", err) + grpclog.Fatalf("Failed to serve: %v", err) } }() addr, stopper := benchmark.StartServer() - log.Println("Server Address: ", addr) + grpclog.Println("Server Address: ", addr) <-time.After(time.Duration(*duration) * time.Second) stopper() } diff --git a/clientconn.go b/clientconn.go index 6080be98..99c2d0c0 100644 --- a/clientconn.go +++ b/clientconn.go @@ -35,7 +35,6 @@ package grpc import ( "errors" - "log" "net" "strings" "sync" @@ -43,6 +42,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/transport" ) @@ -205,8 +205,7 @@ func (cc *ClientConn) resetTransport(closeTransport bool) error { closeTransport = false time.Sleep(sleepTime) retries++ - // TODO(zhaoq): Record the error with glog.V. - log.Printf("grpc: ClientConn.resetTransport failed to create client transport: %v; Reconnecting to %q", err, cc.target) + grpclog.Printf("grpc: ClientConn.resetTransport failed to create client transport: %v; Reconnecting to %q", err, cc.target) continue } cc.mu.Lock() @@ -239,8 +238,7 @@ func (cc *ClientConn) transportMonitor() { case <-cc.transport.Error(): if err := cc.resetTransport(true); err != nil { // The channel is closing. - // TODO(zhaoq): Record the error with glog.V. - log.Printf("grpc: ClientConn.transportMonitor exits due to: %v", err) + grpclog.Printf("grpc: ClientConn.transportMonitor exits due to: %v", err) return } continue diff --git a/examples/route_guide/client/client.go b/examples/route_guide/client/client.go index dfc19da3..51c6c120 100644 --- a/examples/route_guide/client/client.go +++ b/examples/route_guide/client/client.go @@ -40,7 +40,6 @@ package main import ( "flag" "io" - "log" "math/rand" "time" @@ -48,6 +47,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" pb "google.golang.org/grpc/examples/route_guide/proto" + "google.golang.org/grpc/grpclog" ) var ( @@ -59,20 +59,20 @@ var ( // printFeature gets the feature for the given point. func printFeature(client pb.RouteGuideClient, point *pb.Point) { - log.Printf("Getting feature for point (%d, %d)", point.Latitude, point.Longitude) + grpclog.Printf("Getting feature for point (%d, %d)", point.Latitude, point.Longitude) feature, err := client.GetFeature(context.Background(), point) if err != nil { - log.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err) + grpclog.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err) } - log.Println(feature) + grpclog.Println(feature) } // printFeatures lists all the features within the given bounding Rectangle. func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) { - log.Printf("Looking for features within %v", rect) + grpclog.Printf("Looking for features within %v", rect) stream, err := client.ListFeatures(context.Background(), rect) if err != nil { - log.Fatalf("%v.ListFeatures(_) = _, %v", client, err) + grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err) } for { feature, err := stream.Recv() @@ -80,9 +80,9 @@ func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) { break } if err != nil { - log.Fatalf("%v.ListFeatures(_) = _, %v", client, err) + grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err) } - log.Println(feature) + grpclog.Println(feature) } } @@ -95,21 +95,21 @@ func runRecordRoute(client pb.RouteGuideClient) { for i := 0; i < pointCount; i++ { points = append(points, randomPoint(r)) } - log.Printf("Traversing %d points.", len(points)) + grpclog.Printf("Traversing %d points.", len(points)) stream, err := client.RecordRoute(context.Background()) if err != nil { - log.Fatalf("%v.RecordRoute(_) = _, %v", client, err) + grpclog.Fatalf("%v.RecordRoute(_) = _, %v", client, err) } for _, point := range points { if err := stream.Send(point); err != nil { - log.Fatalf("%v.Send(%v) = %v", stream, point, err) + grpclog.Fatalf("%v.Send(%v) = %v", stream, point, err) } } reply, err := stream.CloseAndRecv() if err != nil { - log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil) + grpclog.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil) } - log.Printf("Route summary: %v", reply) + grpclog.Printf("Route summary: %v", reply) } // runRouteChat receives a sequence of route notes, while sending notes for various locations. @@ -124,7 +124,7 @@ func runRouteChat(client pb.RouteGuideClient) { } stream, err := client.RouteChat(context.Background()) if err != nil { - log.Fatalf("%v.RouteChat(_) = _, %v", client, err) + grpclog.Fatalf("%v.RouteChat(_) = _, %v", client, err) } waitc := make(chan struct{}) go func() { @@ -136,14 +136,14 @@ func runRouteChat(client pb.RouteGuideClient) { return } if err != nil { - log.Fatalf("Failed to receive a note : %v", err) + grpclog.Fatalf("Failed to receive a note : %v", err) } - log.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude) + grpclog.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude) } }() for _, note := range notes { if err := stream.Send(note); err != nil { - log.Fatalf("Failed to send a note: %v", err) + grpclog.Fatalf("Failed to send a note: %v", err) } } stream.CloseSend() @@ -169,7 +169,7 @@ func main() { var err error creds, err = credentials.NewClientTLSFromFile(*caFile, sn) if err != nil { - log.Fatalf("Failed to create TLS credentials %v", err) + grpclog.Fatalf("Failed to create TLS credentials %v", err) } } else { creds = credentials.NewClientTLSFromCert(nil, sn) @@ -178,7 +178,7 @@ func main() { } conn, err := grpc.Dial(*serverAddr, opts...) if err != nil { - log.Fatalf("fail to dial: %v", err) + grpclog.Fatalf("fail to dial: %v", err) } defer conn.Close() client := pb.NewRouteGuideClient(conn) diff --git a/examples/route_guide/server/server.go b/examples/route_guide/server/server.go index ff421a6f..cc47fcb5 100644 --- a/examples/route_guide/server/server.go +++ b/examples/route_guide/server/server.go @@ -43,7 +43,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "math" "net" "time" @@ -52,6 +51,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" proto "github.com/golang/protobuf/proto" @@ -159,10 +159,10 @@ func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error func (s *routeGuideServer) loadFeatures(filePath string) { file, err := ioutil.ReadFile(filePath) if err != nil { - log.Fatalf("Failed to load default features: %v", err) + grpclog.Fatalf("Failed to load default features: %v", err) } if err := json.Unmarshal(file, &s.savedFeatures); err != nil { - log.Fatalf("Failed to load default features: %v", err) + grpclog.Fatalf("Failed to load default features: %v", err) } } @@ -223,14 +223,14 @@ func main() { flag.Parse() lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { - log.Fatalf("failed to listen: %v", err) + grpclog.Fatalf("failed to listen: %v", err) } grpcServer := grpc.NewServer() pb.RegisterRouteGuideServer(grpcServer, newServer()) if *tls { creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) if err != nil { - log.Fatalf("Failed to generate credentials %v", err) + grpclog.Fatalf("Failed to generate credentials %v", err) } grpcServer.Serve(creds.NewListener(lis)) } else { diff --git a/grpclog/logger.go b/grpclog/logger.go new file mode 100644 index 00000000..9c7ae449 --- /dev/null +++ b/grpclog/logger.go @@ -0,0 +1,125 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* +Package log defines logging for grpc. +*/ +package grpclog // import "google.golang.org/grpc/grpclog" + +import ( + "log" + "os" + + "github.com/golang/glog" +) + +var ( + // GLogger is a Logger that uses glog. This is the default logger. + GLogger Logger = &glogger{} + + // StdLogger is a Logger that uses golang's standard logger. + StdLogger Logger = log.New(os.Stderr, "", log.LstdFlags) + + logger = GLogger +) + +// Logger mimics golang's standard Logger as an interface. +type Logger interface { + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) + Fatalln(args ...interface{}) + Print(args ...interface{}) + Printf(format string, args ...interface{}) + Println(args ...interface{}) +} + +// SetLogger sets the logger that is used in grpc. +func SetLogger(l Logger) { + logger = l +} + +// Fatal is equivalent to Print() followed by a call to os.Exit() with a non-zero exit code. +func Fatal(args ...interface{}) { + logger.Fatal(args...) +} + +// Fatal is equivalent to Printf() followed by a call to os.Exit() with a non-zero exit code. +func Fatalf(format string, args ...interface{}) { + logger.Fatalf(format, args...) +} + +// Fatal is equivalent to Println() followed by a call to os.Exit()) with a non-zero exit code. +func Fatalln(args ...interface{}) { + logger.Fatalln(args...) +} + +// Print prints to the logger. Arguments are handled in the manner of fmt.Print. +func Print(args ...interface{}) { + logger.Print(args...) +} + +// Printf prints to the logger. Arguments are handled in the manner of fmt.Printf. +func Printf(format string, args ...interface{}) { + logger.Printf(format, args...) +} + +// Println prints to the logger. Arguments are handled in the manner of fmt.Println. +func Println(args ...interface{}) { + logger.Println(args...) +} + +type glogger struct{} + +func (g *glogger) Fatal(args ...interface{}) { + glog.Fatal(args...) +} + +func (g *glogger) Fatalf(format string, args ...interface{}) { + glog.Fatalf(format, args...) +} + +func (g *glogger) Fatalln(args ...interface{}) { + glog.Fatalln(args...) +} + +func (g *glogger) Print(args ...interface{}) { + glog.Info(args...) +} + +func (g *glogger) Printf(format string, args ...interface{}) { + glog.Infof(format, args...) +} + +func (g *glogger) Println(args ...interface{}) { + glog.Infoln(args...) +} diff --git a/interop/client/client.go b/interop/client/client.go index f310d090..1525c8bf 100644 --- a/interop/client/client.go +++ b/interop/client/client.go @@ -37,7 +37,6 @@ import ( "flag" "io" "io/ioutil" - "log" "net" "strconv" "strings" @@ -47,6 +46,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" testpb "google.golang.org/grpc/interop/grpc_testing" "google.golang.org/grpc/metadata" ) @@ -82,15 +82,15 @@ var ( func newPayload(t testpb.PayloadType, size int) *testpb.Payload { if size < 0 { - log.Fatalf("Requested a response with invalid length %d", size) + grpclog.Fatalf("Requested a response with invalid length %d", size) } body := make([]byte, size) switch t { case testpb.PayloadType_COMPRESSABLE: case testpb.PayloadType_UNCOMPRESSABLE: - log.Fatalf("PayloadType UNCOMPRESSABLE is not supported") + grpclog.Fatalf("PayloadType UNCOMPRESSABLE is not supported") default: - log.Fatalf("Unsupported payload type: %d", t) + grpclog.Fatalf("Unsupported payload type: %d", t) } return &testpb.Payload{ Type: t.Enum(), @@ -101,12 +101,12 @@ func newPayload(t testpb.PayloadType, size int) *testpb.Payload { func doEmptyUnaryCall(tc testpb.TestServiceClient) { reply, err := tc.EmptyCall(context.Background(), &testpb.Empty{}) if err != nil { - log.Fatal("/TestService/EmptyCall RPC failed: ", err) + grpclog.Fatal("/TestService/EmptyCall RPC failed: ", err) } if !proto.Equal(&testpb.Empty{}, reply) { - log.Fatalf("/TestService/EmptyCall receives %v, want %v", reply, testpb.Empty{}) + grpclog.Fatalf("/TestService/EmptyCall receives %v, want %v", reply, testpb.Empty{}) } - log.Println("EmptyUnaryCall done") + grpclog.Println("EmptyUnaryCall done") } func doLargeUnaryCall(tc testpb.TestServiceClient) { @@ -118,20 +118,20 @@ func doLargeUnaryCall(tc testpb.TestServiceClient) { } reply, err := tc.UnaryCall(context.Background(), req) if err != nil { - log.Fatal("/TestService/UnaryCall RPC failed: ", err) + grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err) } t := reply.GetPayload().GetType() s := len(reply.GetPayload().GetBody()) if t != testpb.PayloadType_COMPRESSABLE || s != largeRespSize { - log.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, largeRespSize) + grpclog.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, largeRespSize) } - log.Println("LargeUnaryCall done") + grpclog.Println("LargeUnaryCall done") } func doClientStreaming(tc testpb.TestServiceClient) { stream, err := tc.StreamingInputCall(context.Background()) if err != nil { - log.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err) + grpclog.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err) } var sum int for _, s := range reqSizes { @@ -140,20 +140,20 @@ func doClientStreaming(tc testpb.TestServiceClient) { Payload: pl, } if err := stream.Send(req); err != nil { - log.Fatalf("%v.Send(%v) = %v", stream, req, err) + grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err) } sum += s - log.Printf("Sent a request of size %d, aggregated size %d", s, sum) + grpclog.Printf("Sent a request of size %d, aggregated size %d", s, sum) } reply, err := stream.CloseAndRecv() if err != nil { - log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil) + grpclog.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil) } if reply.GetAggregatedPayloadSize() != int32(sum) { - log.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum) + grpclog.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum) } - log.Println("ClientStreaming done") + grpclog.Println("ClientStreaming done") } func doServerStreaming(tc testpb.TestServiceClient) { @@ -169,7 +169,7 @@ func doServerStreaming(tc testpb.TestServiceClient) { } stream, err := tc.StreamingOutputCall(context.Background(), req) if err != nil { - log.Fatalf("%v.StreamingOutputCall(_) = _, %v", tc, err) + grpclog.Fatalf("%v.StreamingOutputCall(_) = _, %v", tc, err) } var rpcStatus error var respCnt int @@ -182,28 +182,28 @@ func doServerStreaming(tc testpb.TestServiceClient) { } t := reply.GetPayload().GetType() if t != testpb.PayloadType_COMPRESSABLE { - log.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE) + grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE) } size := len(reply.GetPayload().GetBody()) if size != int(respSizes[index]) { - log.Fatalf("Got reply body of length %d, want %d", size, respSizes[index]) + grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index]) } index++ respCnt++ } if rpcStatus != io.EOF { - log.Fatalf("Failed to finish the server streaming rpc: %v", err) + grpclog.Fatalf("Failed to finish the server streaming rpc: %v", err) } if respCnt != len(respSizes) { - log.Fatalf("Got %d reply, want %d", len(respSizes), respCnt) + grpclog.Fatalf("Got %d reply, want %d", len(respSizes), respCnt) } - log.Println("ServerStreaming done") + grpclog.Println("ServerStreaming done") } func doPingPong(tc testpb.TestServiceClient) { stream, err := tc.FullDuplexCall(context.Background()) if err != nil { - log.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err) + grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err) } var index int for index < len(reqSizes) { @@ -219,29 +219,29 @@ func doPingPong(tc testpb.TestServiceClient) { Payload: pl, } if err := stream.Send(req); err != nil { - log.Fatalf("%v.Send(%v) = %v", stream, req, err) + grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err) } reply, err := stream.Recv() if err != nil { - log.Fatalf("%v.Recv() = %v", stream, err) + grpclog.Fatalf("%v.Recv() = %v", stream, err) } t := reply.GetPayload().GetType() if t != testpb.PayloadType_COMPRESSABLE { - log.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE) + grpclog.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE) } size := len(reply.GetPayload().GetBody()) if size != int(respSizes[index]) { - log.Fatalf("Got reply body of length %d, want %d", size, respSizes[index]) + grpclog.Fatalf("Got reply body of length %d, want %d", size, respSizes[index]) } index++ } if err := stream.CloseSend(); err != nil { - log.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil) + grpclog.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil) } if _, err := stream.Recv(); err != io.EOF { - log.Fatalf("%v failed to complele the ping pong test: %v", stream, err) + grpclog.Fatalf("%v failed to complele the ping pong test: %v", stream, err) } - log.Println("Pingpong done") + grpclog.Println("Pingpong done") } func doComputeEngineCreds(tc testpb.TestServiceClient) { @@ -255,23 +255,23 @@ func doComputeEngineCreds(tc testpb.TestServiceClient) { } reply, err := tc.UnaryCall(context.Background(), req) if err != nil { - log.Fatal("/TestService/UnaryCall RPC failed: ", err) + grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err) } user := reply.GetUsername() scope := reply.GetOauthScope() if user != *defaultServiceAccount { - log.Fatalf("Got user name %q, want %q.", user, *defaultServiceAccount) + grpclog.Fatalf("Got user name %q, want %q.", user, *defaultServiceAccount) } if !strings.Contains(*oauthScope, scope) { - log.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, *oauthScope) + grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, *oauthScope) } - log.Println("ComputeEngineCreds done") + grpclog.Println("ComputeEngineCreds done") } func getServiceAccountJSONKey() []byte { jsonKey, err := ioutil.ReadFile(*serviceAccountKeyFile) if err != nil { - log.Fatalf("Failed to read the service account key file: %v", err) + grpclog.Fatalf("Failed to read the service account key file: %v", err) } return jsonKey } @@ -287,18 +287,18 @@ func doServiceAccountCreds(tc testpb.TestServiceClient) { } reply, err := tc.UnaryCall(context.Background(), req) if err != nil { - log.Fatal("/TestService/UnaryCall RPC failed: ", err) + grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err) } jsonKey := getServiceAccountJSONKey() user := reply.GetUsername() scope := reply.GetOauthScope() if !strings.Contains(string(jsonKey), user) { - log.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey) + grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey) } if !strings.Contains(*oauthScope, scope) { - log.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, *oauthScope) + grpclog.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, *oauthScope) } - log.Println("ServiceAccountCreds done") + grpclog.Println("ServiceAccountCreds done") } var ( @@ -312,21 +312,21 @@ func doCancelAfterBegin(tc testpb.TestServiceClient) { ctx, cancel := context.WithCancel(metadata.NewContext(context.Background(), testMetadata)) stream, err := tc.StreamingInputCall(ctx) if err != nil { - log.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err) + grpclog.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err) } cancel() _, err = stream.CloseAndRecv() if grpc.Code(err) != codes.Canceled { - log.Fatalf("%v.CloseAndRecv() got error code %d, want %d", stream, grpc.Code(err), codes.Canceled) + grpclog.Fatalf("%v.CloseAndRecv() got error code %d, want %d", stream, grpc.Code(err), codes.Canceled) } - log.Println("CancelAfterBegin done") + grpclog.Println("CancelAfterBegin done") } func doCancelAfterFirstResponse(tc testpb.TestServiceClient) { ctx, cancel := context.WithCancel(context.Background()) stream, err := tc.FullDuplexCall(ctx) if err != nil { - log.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err) + grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err) } respParam := []*testpb.ResponseParameters{ { @@ -340,16 +340,16 @@ func doCancelAfterFirstResponse(tc testpb.TestServiceClient) { Payload: pl, } if err := stream.Send(req); err != nil { - log.Fatalf("%v.Send(%v) = %v", stream, req, err) + grpclog.Fatalf("%v.Send(%v) = %v", stream, req, err) } if _, err := stream.Recv(); err != nil { - log.Fatalf("%v.Recv() = %v", stream, err) + grpclog.Fatalf("%v.Recv() = %v", stream, err) } cancel() if _, err := stream.Recv(); grpc.Code(err) != codes.Canceled { - log.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), codes.Canceled) + grpclog.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), codes.Canceled) } - log.Println("CancelAfterFirstResponse done") + grpclog.Println("CancelAfterFirstResponse done") } func main() { @@ -366,7 +366,7 @@ func main() { var err error creds, err = credentials.NewClientTLSFromFile(*caFile, sn) if err != nil { - log.Fatalf("Failed to create TLS credentials %v", err) + grpclog.Fatalf("Failed to create TLS credentials %v", err) } } else { creds = credentials.NewClientTLSFromCert(nil, sn) @@ -377,14 +377,14 @@ func main() { } else if *testCase == "service_account_creds" { jwtCreds, err := credentials.NewServiceAccountFromFile(*serviceAccountKeyFile, *oauthScope) if err != nil { - log.Fatalf("Failed to create JWT credentials: %v", err) + grpclog.Fatalf("Failed to create JWT credentials: %v", err) } opts = append(opts, grpc.WithPerRPCCredentials(jwtCreds)) } } conn, err := grpc.Dial(serverAddr, opts...) if err != nil { - log.Fatalf("Fail to dial: %v", err) + grpclog.Fatalf("Fail to dial: %v", err) } defer conn.Close() tc := testpb.NewTestServiceClient(conn) @@ -401,12 +401,12 @@ func main() { doPingPong(tc) case "compute_engine_creds": if !*useTLS { - log.Fatalf("TLS is not enabled. TLS is required to execute compute_engine_creds test case.") + grpclog.Fatalf("TLS is not enabled. TLS is required to execute compute_engine_creds test case.") } doComputeEngineCreds(tc) case "service_account_creds": if !*useTLS { - log.Fatalf("TLS is not enabled. TLS is required to execute service_account_creds test case.") + grpclog.Fatalf("TLS is not enabled. TLS is required to execute service_account_creds test case.") } doServiceAccountCreds(tc) case "cancel_after_begin": @@ -414,6 +414,6 @@ func main() { case "cancel_after_first_response": doCancelAfterFirstResponse(tc) default: - log.Fatal("Unsupported test case: ", *testCase) + grpclog.Fatal("Unsupported test case: ", *testCase) } } diff --git a/interop/server/server.go b/interop/server/server.go index d07b4cfe..4c79cb18 100644 --- a/interop/server/server.go +++ b/interop/server/server.go @@ -37,7 +37,6 @@ import ( "flag" "fmt" "io" - "log" "net" "strconv" "time" @@ -46,6 +45,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" testpb "google.golang.org/grpc/interop/grpc_testing" ) @@ -193,14 +193,14 @@ func main() { p := strconv.Itoa(*port) lis, err := net.Listen("tcp", ":"+p) if err != nil { - log.Fatalf("failed to listen: %v", err) + grpclog.Fatalf("failed to listen: %v", err) } server := grpc.NewServer() testpb.RegisterTestServiceServer(server, &testServer{}) if *useTLS { creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) if err != nil { - log.Fatalf("Failed to generate credentials %v", err) + grpclog.Fatalf("Failed to generate credentials %v", err) } server.Serve(creds.NewListener(lis)) } else { diff --git a/server.go b/server.go index c8e677e2..a8be7639 100644 --- a/server.go +++ b/server.go @@ -37,7 +37,6 @@ import ( "errors" "fmt" "io" - "log" "net" "reflect" "strings" @@ -45,6 +44,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/metadata" "google.golang.org/grpc/transport" ) @@ -143,12 +143,12 @@ func (s *Server) RegisterService(sd *ServiceDesc, ss interface{}) { defer s.mu.Unlock() // Does some sanity checks. if _, ok := s.m[sd.ServiceName]; ok { - log.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName) + grpclog.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName) } ht := reflect.TypeOf(sd.HandlerType).Elem() st := reflect.TypeOf(ss) if !st.Implements(ht) { - log.Fatalf("grpc: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht) + grpclog.Fatalf("grpc: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht) } srv := &service{ server: ss, @@ -198,7 +198,7 @@ func (s *Server) Serve(lis net.Listener) error { // Perform handshaking if it is required. if s.opts.handshaker != nil { if err := s.opts.handshaker(c); err != nil { - log.Println("grpc: Server.Serve failed to complete handshake.") + grpclog.Println("grpc: Server.Serve failed to complete handshake.") c.Close() continue } @@ -213,7 +213,7 @@ func (s *Server) Serve(lis net.Listener) error { if err != nil { s.mu.Unlock() c.Close() - log.Println("grpc: Server.Serve failed to create ServerTransport: ", err) + grpclog.Println("grpc: Server.Serve failed to create ServerTransport: ", err) continue } s.conns[st] = true @@ -240,7 +240,7 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str // TODO(zhaoq): There exist other options also such as only closing the // faulty stream locally and remotely (Other streams can keep going). Find // the optimal option. - log.Fatalf("grpc: Server failed to encode response %v", err) + grpclog.Fatalf("grpc: Server failed to encode response %v", err) } return t.Write(stream, p, opts) } @@ -259,7 +259,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. // Nothing to do here. case transport.StreamError: if err := t.WriteStatus(stream, err.Code, err.Desc); err != nil { - log.Printf("grpc: Server.processUnaryRPC failed to write status: %v", err) + grpclog.Printf("grpc: Server.processUnaryRPC failed to write status: %v", err) } default: panic(fmt.Sprintf("grpc: Unexpected error (%T) from recvMsg: %v", err, err)) @@ -280,7 +280,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. statusDesc = appErr.Error() } if err := t.WriteStatus(stream, statusCode, statusDesc); err != nil { - log.Printf("grpc: Server.processUnaryRPC failed to write status: %v", err) + grpclog.Printf("grpc: Server.processUnaryRPC failed to write status: %v", err) } return } @@ -334,7 +334,7 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str pos := strings.LastIndex(sm, "/") if pos == -1 { if err := t.WriteStatus(stream, codes.InvalidArgument, fmt.Sprintf("malformed method name: %q", stream.Method())); err != nil { - log.Printf("grpc: Server.handleStream failed to write status: %v", err) + grpclog.Printf("grpc: Server.handleStream failed to write status: %v", err) } return } @@ -343,7 +343,7 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str srv, ok := s.m[service] if !ok { if err := t.WriteStatus(stream, codes.Unimplemented, fmt.Sprintf("unknown service %v", service)); err != nil { - log.Printf("grpc: Server.handleStream failed to write status: %v", err) + grpclog.Printf("grpc: Server.handleStream failed to write status: %v", err) } return } @@ -357,7 +357,7 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str return } if err := t.WriteStatus(stream, codes.Unimplemented, fmt.Sprintf("unknown method %v", method)); err != nil { - log.Printf("grpc: Server.handleStream failed to write status: %v", err) + grpclog.Printf("grpc: Server.handleStream failed to write status: %v", err) } } @@ -401,7 +401,7 @@ func SendHeader(ctx context.Context, md metadata.MD) error { } t := stream.ServerTransport() if t == nil { - log.Fatalf("grpc: SendHeader: %v has no ServerTransport to send header metadata.", stream) + grpclog.Fatalf("grpc: SendHeader: %v has no ServerTransport to send header metadata.", stream) } return t.WriteHeader(stream, md) } diff --git a/test/end2end_test.go b/test/end2end_test.go index 3d41c610..ded266c7 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -36,7 +36,6 @@ package grpc_test import ( "fmt" "io" - "log" "math" "net" "reflect" @@ -51,6 +50,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/metadata" testpb "google.golang.org/grpc/test/grpc_testing" ) @@ -75,15 +75,15 @@ func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.E func newPayload(t testpb.PayloadType, size int32) *testpb.Payload { if size < 0 { - log.Fatalf("Requested a response with invalid length %d", size) + grpclog.Fatalf("Requested a response with invalid length %d", size) } body := make([]byte, size) switch t { case testpb.PayloadType_COMPRESSABLE: case testpb.PayloadType_UNCOMPRESSABLE: - log.Fatalf("PayloadType UNCOMPRESSABLE is not supported") + grpclog.Fatalf("PayloadType UNCOMPRESSABLE is not supported") default: - log.Fatalf("Unsupported payload type: %d", t) + grpclog.Fatalf("Unsupported payload type: %d", t) } return &testpb.Payload{ Type: t.Enum(), @@ -95,7 +95,7 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (* md, ok := metadata.FromContext(ctx) if ok { if err := grpc.SendHeader(ctx, md); err != nil { - log.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil) + grpclog.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil) } grpc.SetTrailer(ctx, md) } @@ -146,7 +146,7 @@ func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServ md, ok := metadata.FromContext(stream.Context()) if ok { if err := stream.SendHeader(md); err != nil { - log.Fatalf("%v.SendHeader(%v) = %v, want %v", stream, md, err, nil) + grpclog.Fatalf("%v.SendHeader(%v) = %v, want %v", stream, md, err, nil) } stream.SetTrailer(md) } @@ -293,13 +293,13 @@ func setUp(maxStream uint32, e env) (s *grpc.Server, cc *grpc.ClientConn) { } lis, err := net.Listen(e.network, la) if err != nil { - log.Fatalf("Failed to listen: %v", err) + grpclog.Fatalf("Failed to listen: %v", err) } testpb.RegisterTestServiceServer(s, &testServer{}) if e.security == "tls" { creds, err := credentials.NewServerTLSFromFile(tlsDir+"server1.pem", tlsDir+"server1.key") if err != nil { - log.Fatalf("Failed to generate credentials %v", err) + grpclog.Fatalf("Failed to generate credentials %v", err) } go s.Serve(creds.NewListener(lis)) } else { @@ -311,21 +311,21 @@ func setUp(maxStream uint32, e env) (s *grpc.Server, cc *grpc.ClientConn) { default: _, port, err := net.SplitHostPort(lis.Addr().String()) if err != nil { - log.Fatalf("Failed to parse listener address: %v", err) + grpclog.Fatalf("Failed to parse listener address: %v", err) } addr = "localhost:" + port } if e.security == "tls" { creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com") if err != nil { - log.Fatalf("Failed to create credentials %v", err) + grpclog.Fatalf("Failed to create credentials %v", err) } cc, err = grpc.Dial(addr, grpc.WithTransportCredentials(creds), grpc.WithDialer(e.dialer)) } else { cc, err = grpc.Dial(addr, grpc.WithDialer(e.dialer)) } if err != nil { - log.Fatalf("Dial(%q) = %v", addr, err) + grpclog.Fatalf("Dial(%q) = %v", addr, err) } return } diff --git a/transport/http2_client.go b/transport/http2_client.go index 5de498fe..0a7dd70e 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -37,7 +37,6 @@ import ( "bytes" "errors" "io" - "log" "math" "net" "sync" @@ -48,6 +47,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/metadata" ) @@ -553,7 +553,7 @@ func (t *http2Client) handleRSTStream(f *http2.RSTStreamFrame) { s.state = streamDone s.statusCode, ok = http2RSTErrConvTab[http2.ErrCode(f.ErrCode)] if !ok { - log.Println("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error ", f.ErrCode) + grpclog.Println("transport: http2Client.handleRSTStream found no mapped gRPC status for the received http2 error ", f.ErrCode) } s.mu.Unlock() s.write(recvMsg{err: io.EOF}) @@ -703,7 +703,7 @@ func (t *http2Client) reader() { case *http2.WindowUpdateFrame: t.handleWindowUpdate(frame) default: - log.Printf("transport: http2Client.reader got unhandled frame type %v.", frame) + grpclog.Printf("transport: http2Client.reader got unhandled frame type %v.", frame) } } } @@ -735,7 +735,7 @@ func (t *http2Client) controller() { // meaningful content when this is actually in use. t.framer.writePing(true, i.ack, [8]byte{}) default: - log.Printf("transport: http2Client.controller got unexpected item type %v\n", i) + grpclog.Printf("transport: http2Client.controller got unexpected item type %v\n", i) } t.writableChan <- 0 continue @@ -759,6 +759,6 @@ func (t *http2Client) notifyError(err error) { if t.state == reachable { t.state = unreachable close(t.errorChan) - log.Printf("transport: http2Client.notifyError got notified that the client transport was broken %v.", err) + grpclog.Printf("transport: http2Client.notifyError got notified that the client transport was broken %v.", err) } } diff --git a/transport/http2_server.go b/transport/http2_server.go index ef1a872e..d9c0e111 100644 --- a/transport/http2_server.go +++ b/transport/http2_server.go @@ -37,7 +37,6 @@ import ( "bytes" "errors" "io" - "log" "math" "net" "strconv" @@ -47,6 +46,7 @@ import ( "github.com/bradfitz/http2/hpack" "golang.org/x/net/context" "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/metadata" ) @@ -149,7 +149,7 @@ func (t *http2Server) operateHeaders(hDec *hpackDecoder, s *Stream, frame header return nil } if err != nil { - log.Printf("transport: http2Server.operateHeader found %v", err) + grpclog.Printf("transport: http2Server.operateHeader found %v", err) if se, ok := err.(StreamError); ok { t.controlBuf.put(&resetStream{s.id, statusCodeConvTab[se.Code]}) } @@ -212,25 +212,25 @@ func (t *http2Server) HandleStreams(handle func(*Stream)) { // Check the validity of client preface. preface := make([]byte, len(clientPreface)) if _, err := io.ReadFull(t.conn, preface); err != nil { - log.Printf("transport: http2Server.HandleStreams failed to receive the preface from client: %v", err) + grpclog.Printf("transport: http2Server.HandleStreams failed to receive the preface from client: %v", err) t.Close() return } if !bytes.Equal(preface, clientPreface) { - log.Printf("transport: http2Server.HandleStreams received bogus greeting from client: %q", preface) + grpclog.Printf("transport: http2Server.HandleStreams received bogus greeting from client: %q", preface) t.Close() return } frame, err := t.framer.readFrame() if err != nil { - log.Printf("transport: http2Server.HandleStreams failed to read frame: %v", err) + grpclog.Printf("transport: http2Server.HandleStreams failed to read frame: %v", err) t.Close() return } sf, ok := frame.(*http2.SettingsFrame) if !ok { - log.Printf("transport: http2Server.HandleStreams saw invalid preface type %T from client", frame) + grpclog.Printf("transport: http2Server.HandleStreams saw invalid preface type %T from client", frame) t.Close() return } @@ -251,7 +251,7 @@ func (t *http2Server) HandleStreams(handle func(*Stream)) { id := frame.Header().StreamID if id%2 != 1 || id <= t.maxStreamID { // illegal gRPC stream id. - log.Println("transport: http2Server.HandleStreams received an illegal stream id: ", id) + grpclog.Println("transport: http2Server.HandleStreams received an illegal stream id: ", id) t.Close() break } @@ -284,7 +284,7 @@ func (t *http2Server) HandleStreams(handle func(*Stream)) { case *http2.GoAwayFrame: break default: - log.Printf("transport: http2Server.HandleStreams found unhandled frame type %v.", frame) + grpclog.Printf("transport: http2Server.HandleStreams found unhandled frame type %v.", frame) } } } @@ -326,7 +326,7 @@ func (t *http2Server) handleData(f *http2.DataFrame) { size := len(f.Data()) if err := s.fc.onData(uint32(size)); err != nil { if _, ok := err.(ConnectionError); ok { - log.Printf("transport: http2Server %v", err) + grpclog.Printf("transport: http2Server %v", err) t.Close() return } @@ -611,7 +611,7 @@ func (t *http2Server) controller() { // meaningful content when this is actually in use. t.framer.writePing(true, i.ack, [8]byte{}) default: - log.Printf("transport: http2Server.controller got unexpected item type %v\n", i) + grpclog.Printf("transport: http2Server.controller got unexpected item type %v\n", i) } t.writableChan <- 0 continue diff --git a/transport/http_util.go b/transport/http_util.go index fb67a0d2..2babe729 100644 --- a/transport/http_util.go +++ b/transport/http_util.go @@ -37,7 +37,6 @@ import ( "bufio" "fmt" "io" - "log" "net" "strconv" "sync/atomic" @@ -46,6 +45,7 @@ import ( "github.com/bradfitz/http2" "github.com/bradfitz/http2/hpack" "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" "google.golang.org/grpc/metadata" ) @@ -166,7 +166,7 @@ func newHPACKDecoder() *hpackDecoder { } k, v, err := metadata.DecodeKeyValue(f.Name, f.Value) if err != nil { - log.Printf("Failed to decode (%q, %q): %v", f.Name, f.Value, err) + grpclog.Printf("Failed to decode (%q, %q): %v", f.Name, f.Value, err) return } d.state.mdata[k] = v diff --git a/transport/transport_test.go b/transport/transport_test.go index d418420c..22fc1d7e 100644 --- a/transport/transport_test.go +++ b/transport/transport_test.go @@ -36,7 +36,6 @@ package transport import ( "bytes" "io" - "log" "math" "net" "reflect" @@ -49,6 +48,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/grpclog" ) type server struct { @@ -93,7 +93,7 @@ func (h *testStreamHandler) handleStream(s *Stream) { if err == ErrConnClosing { return } - log.Fatalf("handleStream got error: %v, want ; result: %v, want %v", err, p, req) + grpclog.Fatalf("handleStream got error: %v, want ; result: %v, want %v", err, p, req) } // send a response back to the client. h.t.Write(s, resp, &Options{}) @@ -109,7 +109,7 @@ func (h *testStreamHandler) handleStreamSuspension(s *Stream) { func (h *testStreamHandler) handleStreamMisbehave(s *Stream) { conn, ok := s.ServerTransport().(*http2Server) if !ok { - log.Fatalf("Failed to convert %v to *http2Server", s.ServerTransport()) + grpclog.Fatalf("Failed to convert %v to *http2Server", s.ServerTransport()) } size := 1 if s.Method() == "foo.MaxFrame" { @@ -137,18 +137,18 @@ func (s *server) start(useTLS bool, port int, maxStreams uint32, ht hType) { s.lis, err = net.Listen("tcp", ":"+strconv.Itoa(port)) } if err != nil { - log.Fatalf("failed to listen: %v", err) + grpclog.Fatalf("failed to listen: %v", err) } if useTLS { creds, err := credentials.NewServerTLSFromFile(tlsDir+"server1.pem", tlsDir+"server1.key") if err != nil { - log.Fatalf("Failed to generate credentials %v", err) + grpclog.Fatalf("Failed to generate credentials %v", err) } s.lis = creds.NewListener(s.lis) } _, p, err := net.SplitHostPort(s.lis.Addr().String()) if err != nil { - log.Fatalf("failed to parse listener address: %v", err) + grpclog.Fatalf("failed to parse listener address: %v", err) } s.port = p s.conns = make(map[ServerTransport]bool)