vitess.io/vitess@v0.16.2/go/vt/grpcclient/glogger.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package grpcclient 18 19 import ( 20 "fmt" 21 22 "google.golang.org/grpc/grpclog" 23 24 "vitess.io/vitess/go/vt/log" 25 ) 26 27 // grpc doesn't return underlying errors. So, we have 28 // to rely on logs to know the root cause if a request 29 // fails. Using grpc's glogger is too spammy. So, we 30 // perform more selective logging using these functions. 31 func init() { 32 grpclog.SetLoggerV2(&glogger{}) 33 } 34 35 type glogger struct{} 36 37 func (g *glogger) Info(args ...any) { 38 } 39 40 func (g *glogger) Infoln(args ...any) { 41 } 42 43 func (g *glogger) Infof(format string, args ...any) { 44 } 45 46 func (g *glogger) Warning(args ...any) { 47 log.WarningDepth(2, args...) 48 } 49 50 func (g *glogger) Warningln(args ...any) { 51 log.WarningDepth(2, fmt.Sprintln(args...)) 52 } 53 54 func (g *glogger) Warningf(format string, args ...any) { 55 log.WarningDepth(2, fmt.Sprintf(format, args...)) 56 } 57 58 func (g *glogger) Error(args ...any) { 59 log.ErrorDepth(2, args...) 60 } 61 62 func (g *glogger) Errorln(args ...any) { 63 log.ErrorDepth(2, fmt.Sprintln(args...)) 64 } 65 66 func (g *glogger) Errorf(format string, args ...any) { 67 log.ErrorDepth(2, fmt.Sprintf(format, args...)) 68 } 69 70 func (g *glogger) Fatal(args ...any) { 71 log.FatalDepth(2, args...) 72 } 73 74 func (g *glogger) Fatalln(args ...any) { 75 log.FatalDepth(2, fmt.Sprintln(args...)) 76 } 77 78 func (g *glogger) Fatalf(format string, args ...any) { 79 log.FatalDepth(2, fmt.Sprintf(format, args...)) 80 } 81 82 func (g *glogger) V(l int) bool { 83 return bool(log.V(log.Level(l))) 84 }