google.golang.org/grpc@v1.62.1/grpclog/glogger/glogger.go (about) 1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // Package glogger defines glog-based logging for grpc. 20 // Importing this package will install glog as the logger used by grpclog. 21 package glogger 22 23 import ( 24 "fmt" 25 26 "github.com/golang/glog" 27 "google.golang.org/grpc/grpclog" 28 ) 29 30 const d = 2 31 32 func init() { 33 grpclog.SetLoggerV2(&glogger{}) 34 } 35 36 type glogger struct{} 37 38 func (g *glogger) Info(args ...any) { 39 glog.InfoDepth(d, args...) 40 } 41 42 func (g *glogger) Infoln(args ...any) { 43 glog.InfoDepth(d, fmt.Sprintln(args...)) 44 } 45 46 func (g *glogger) Infof(format string, args ...any) { 47 glog.InfoDepth(d, fmt.Sprintf(format, args...)) 48 } 49 50 func (g *glogger) InfoDepth(depth int, args ...any) { 51 glog.InfoDepth(depth+d, args...) 52 } 53 54 func (g *glogger) Warning(args ...any) { 55 glog.WarningDepth(d, args...) 56 } 57 58 func (g *glogger) Warningln(args ...any) { 59 glog.WarningDepth(d, fmt.Sprintln(args...)) 60 } 61 62 func (g *glogger) Warningf(format string, args ...any) { 63 glog.WarningDepth(d, fmt.Sprintf(format, args...)) 64 } 65 66 func (g *glogger) WarningDepth(depth int, args ...any) { 67 glog.WarningDepth(depth+d, args...) 68 } 69 70 func (g *glogger) Error(args ...any) { 71 glog.ErrorDepth(d, args...) 72 } 73 74 func (g *glogger) Errorln(args ...any) { 75 glog.ErrorDepth(d, fmt.Sprintln(args...)) 76 } 77 78 func (g *glogger) Errorf(format string, args ...any) { 79 glog.ErrorDepth(d, fmt.Sprintf(format, args...)) 80 } 81 82 func (g *glogger) ErrorDepth(depth int, args ...any) { 83 glog.ErrorDepth(depth+d, args...) 84 } 85 86 func (g *glogger) Fatal(args ...any) { 87 glog.FatalDepth(d, args...) 88 } 89 90 func (g *glogger) Fatalln(args ...any) { 91 glog.FatalDepth(d, fmt.Sprintln(args...)) 92 } 93 94 func (g *glogger) Fatalf(format string, args ...any) { 95 glog.FatalDepth(d, fmt.Sprintf(format, args...)) 96 } 97 98 func (g *glogger) FatalDepth(depth int, args ...any) { 99 glog.FatalDepth(depth+d, args...) 100 } 101 102 func (g *glogger) V(l int) bool { 103 return bool(glog.V(glog.Level(l))) 104 }