cubefs

Форк
0
102 строки · 2.5 Кб
1
/*
2
 *
3
 * Copyright 2020 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 channelz
20

21
import (
22
	"fmt"
23

24
	"google.golang.org/grpc/grpclog"
25
)
26

27
var logger = grpclog.Component("channelz")
28

29
// Info logs and adds a trace event if channelz is on.
30
func Info(l grpclog.DepthLoggerV2, id int64, args ...interface{}) {
31
	if IsOn() {
32
		AddTraceEvent(l, id, 1, &TraceEventDesc{
33
			Desc:     fmt.Sprint(args...),
34
			Severity: CtInfo,
35
		})
36
	} else {
37
		l.InfoDepth(1, args...)
38
	}
39
}
40

41
// Infof logs and adds a trace event if channelz is on.
42
func Infof(l grpclog.DepthLoggerV2, id int64, format string, args ...interface{}) {
43
	msg := fmt.Sprintf(format, args...)
44
	if IsOn() {
45
		AddTraceEvent(l, id, 1, &TraceEventDesc{
46
			Desc:     msg,
47
			Severity: CtInfo,
48
		})
49
	} else {
50
		l.InfoDepth(1, msg)
51
	}
52
}
53

54
// Warning logs and adds a trace event if channelz is on.
55
func Warning(l grpclog.DepthLoggerV2, id int64, args ...interface{}) {
56
	if IsOn() {
57
		AddTraceEvent(l, id, 1, &TraceEventDesc{
58
			Desc:     fmt.Sprint(args...),
59
			Severity: CtWarning,
60
		})
61
	} else {
62
		l.WarningDepth(1, args...)
63
	}
64
}
65

66
// Warningf logs and adds a trace event if channelz is on.
67
func Warningf(l grpclog.DepthLoggerV2, id int64, format string, args ...interface{}) {
68
	msg := fmt.Sprintf(format, args...)
69
	if IsOn() {
70
		AddTraceEvent(l, id, 1, &TraceEventDesc{
71
			Desc:     msg,
72
			Severity: CtWarning,
73
		})
74
	} else {
75
		l.WarningDepth(1, msg)
76
	}
77
}
78

79
// Error logs and adds a trace event if channelz is on.
80
func Error(l grpclog.DepthLoggerV2, id int64, args ...interface{}) {
81
	if IsOn() {
82
		AddTraceEvent(l, id, 1, &TraceEventDesc{
83
			Desc:     fmt.Sprint(args...),
84
			Severity: CtError,
85
		})
86
	} else {
87
		l.ErrorDepth(1, args...)
88
	}
89
}
90

91
// Errorf logs and adds a trace event if channelz is on.
92
func Errorf(l grpclog.DepthLoggerV2, id int64, format string, args ...interface{}) {
93
	msg := fmt.Sprintf(format, args...)
94
	if IsOn() {
95
		AddTraceEvent(l, id, 1, &TraceEventDesc{
96
			Desc:     msg,
97
			Severity: CtError,
98
		})
99
	} else {
100
		l.ErrorDepth(1, msg)
101
	}
102
}
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.