| 1 |
/* |
| 2 |
Copyright 2018 The Kubernetes 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 etcd3 |
| 18 |
|
| 19 |
import ( |
| 20 |
"fmt" |
| 21 |
|
| 22 |
"google.golang.org/grpc/grpclog" |
| 23 |
"k8s.io/klog/v2" |
| 24 |
) |
| 25 |
|
| 26 |
func init() { |
| 27 |
grpclog.SetLoggerV2(klogWrapper{}) |
| 28 |
} |
| 29 |
|
| 30 |
type klogWrapper struct{} |
| 31 |
|
| 32 |
const klogWrapperDepth = 4 |
| 33 |
|
| 34 |
func (klogWrapper) Info(args ...interface{}) { |
| 35 |
if klogV := klog.V(5); klogV.Enabled() { |
| 36 |
klogV.InfoSDepth(klogWrapperDepth, fmt.Sprint(args...)) |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func (klogWrapper) Infoln(args ...interface{}) { |
| 41 |
if klogV := klog.V(5); klogV.Enabled() { |
| 42 |
klogV.InfoSDepth(klogWrapperDepth, fmt.Sprintln(args...)) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func (klogWrapper) Infof(format string, args ...interface{}) { |
| 47 |
if klogV := klog.V(5); klogV.Enabled() { |
| 48 |
klog.V(5).InfoSDepth(klogWrapperDepth, fmt.Sprintf(format, args...)) |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
func (klogWrapper) Warning(args ...interface{}) { |
| 53 |
klog.WarningDepth(klogWrapperDepth, args...) |
| 54 |
} |
| 55 |
|
| 56 |
func (klogWrapper) Warningln(args ...interface{}) { |
| 57 |
klog.WarningDepth(klogWrapperDepth, fmt.Sprintln(args...)) |
| 58 |
} |
| 59 |
|
| 60 |
func (klogWrapper) Warningf(format string, args ...interface{}) { |
| 61 |
klog.WarningDepth(klogWrapperDepth, fmt.Sprintf(format, args...)) |
| 62 |
} |
| 63 |
|
| 64 |
func (klogWrapper) Error(args ...interface{}) { |
| 65 |
klog.ErrorDepth(klogWrapperDepth, args...) |
| 66 |
} |
| 67 |
|
| 68 |
func (klogWrapper) Errorln(args ...interface{}) { |
| 69 |
klog.ErrorDepth(klogWrapperDepth, fmt.Sprintln(args...)) |
| 70 |
} |
| 71 |
|
| 72 |
func (klogWrapper) Errorf(format string, args ...interface{}) { |
| 73 |
klog.ErrorDepth(klogWrapperDepth, fmt.Sprintf(format, args...)) |
| 74 |
} |
| 75 |
|
| 76 |
func (klogWrapper) Fatal(args ...interface{}) { |
| 77 |
klog.FatalDepth(klogWrapperDepth, args...) |
| 78 |
} |
| 79 |
|
| 80 |
func (klogWrapper) Fatalln(args ...interface{}) { |
| 81 |
klog.FatalDepth(klogWrapperDepth, fmt.Sprintln(args...)) |
| 82 |
} |
| 83 |
|
| 84 |
func (klogWrapper) Fatalf(format string, args ...interface{}) { |
| 85 |
klog.FatalDepth(klogWrapperDepth, fmt.Sprintf(format, args...)) |
| 86 |
} |
| 87 |
|
| 88 |
func (klogWrapper) V(l int) bool { |
| 89 |
return bool(klog.V(klog.Level(l)).Enabled()) |
| 90 |
} |