dubbo.apache.org/dubbo-go/v3@v3.1.1/xds/utils/grpclog/grpclog.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. 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 * 20 * Copyright 2020 gRPC authors. 21 * 22 */ 23 24 // Package grpclog (internal) defines depth logging for grpc. 25 package grpclog 26 27 import ( 28 "os" 29 ) 30 31 import ( 32 "github.com/dubbogo/gost/log/logger" 33 ) 34 35 // Logger is the logger used for the non-depth log functions. 36 var Logger = func() logger.Logger { 37 logger.InitLogger(&logger.Config{ 38 CallerSkip: 2, 39 }) 40 return logger.GetLogger() 41 }() 42 43 // DepthLogger is the logger used for the depth log functions. 44 var DepthLogger DepthLoggerV2 45 46 // InfoDepth logs to the INFO log at the specified depth. 47 func InfoDepth(depth int, args ...interface{}) { 48 if DepthLogger != nil { 49 DepthLogger.InfoDepth(depth, args...) 50 } else { 51 Logger.Info(args...) 52 } 53 } 54 55 // WarningDepth logs to the WARNING log at the specified depth. 56 func WarningDepth(depth int, args ...interface{}) { 57 if DepthLogger != nil { 58 DepthLogger.WarningDepth(depth, args...) 59 } else { 60 Logger.Warn(args...) 61 } 62 } 63 64 // ErrorDepth logs to the ERROR log at the specified depth. 65 func ErrorDepth(depth int, args ...interface{}) { 66 if DepthLogger != nil { 67 DepthLogger.ErrorDepth(depth, args...) 68 } else { 69 Logger.Error(args...) 70 } 71 } 72 73 // FatalDepth logs to the FATAL log at the specified depth. 74 func FatalDepth(depth int, args ...interface{}) { 75 if DepthLogger != nil { 76 DepthLogger.FatalDepth(depth, args...) 77 } else { 78 Logger.Fatal(args...) 79 } 80 os.Exit(1) 81 } 82 83 // LoggerV2 does underlying logging work for grpclog. 84 // This is a copy of the LoggerV2 defined in the external grpclog package. It 85 // is defined here to avoid a circular dependency. 86 type LoggerV2 interface { 87 // Info logs to INFO log. Arguments are handled in the manner of fmt.Print. 88 Info(args ...interface{}) 89 // Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println. 90 Infoln(args ...interface{}) 91 // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. 92 Infof(format string, args ...interface{}) 93 // Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print. 94 Warning(args ...interface{}) 95 // Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println. 96 Warningln(args ...interface{}) 97 // Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf. 98 Warnf(format string, args ...interface{}) 99 // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print. 100 Error(args ...interface{}) 101 // Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println. 102 Errorln(args ...interface{}) 103 // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. 104 Errorf(format string, args ...interface{}) 105 // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print. 106 // gRPC ensures that all Fatal logs will exit with os.Exit(1). 107 // Implementations may also call os.Exit() with a non-zero exit code. 108 Fatal(args ...interface{}) 109 // Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println. 110 // gRPC ensures that all Fatal logs will exit with os.Exit(1). 111 // Implementations may also call os.Exit() with a non-zero exit code. 112 Fatalln(args ...interface{}) 113 // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. 114 // gRPC ensures that all Fatal logs will exit with os.Exit(1). 115 // Implementations may also call os.Exit() with a non-zero exit code. 116 Fatalf(format string, args ...interface{}) 117 // V reports whether verbosity level l is at least the requested verbose level. 118 V(l int) bool 119 } 120 121 // DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements 122 // DepthLoggerV2, the below functions will be called with the appropriate stack 123 // depth set for trivial functions the logger may ignore. 124 // This is a copy of the DepthLoggerV2 defined in the external grpclog package. 125 // It is defined here to avoid a circular dependency. 126 // 127 // # Experimental 128 // 129 // Notice: This type is EXPERIMENTAL and may be changed or removed in a 130 // later release. 131 type DepthLoggerV2 interface { 132 // InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println. 133 InfoDepth(depth int, args ...interface{}) 134 // WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println. 135 WarningDepth(depth int, args ...interface{}) 136 // ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println. 137 ErrorDepth(depth int, args ...interface{}) 138 // FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println. 139 FatalDepth(depth int, args ...interface{}) 140 }