forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callerInfo.go
59 lines (50 loc) · 1.62 KB
/
callerInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package metadata
import "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
type callerInfoKey struct {
module string
level api.Level
}
//CallerInfo maintains module-level based information to toggle caller info
type CallerInfo struct {
showcaller map[callerInfoKey]bool
}
//ShowCallerInfo enables caller info for given module and level
func (l *CallerInfo) ShowCallerInfo(module string, level api.Level) {
if l.showcaller == nil {
l.showcaller = l.getDefaultCallerInfoSetting()
}
l.showcaller[callerInfoKey{module, level}] = true
}
//HideCallerInfo disables caller info for given module and level
func (l *CallerInfo) HideCallerInfo(module string, level api.Level) {
if l.showcaller == nil {
l.showcaller = l.getDefaultCallerInfoSetting()
}
l.showcaller[callerInfoKey{module, level}] = false
}
//IsCallerInfoEnabled returns if callerinfo enabled for given module and level
func (l *CallerInfo) IsCallerInfoEnabled(module string, level api.Level) bool {
showcaller, exists := l.showcaller[callerInfoKey{module, level}]
if !exists {
//If no callerinfo setting exists, then look for default
showcaller, exists = l.showcaller[callerInfoKey{"", level}]
if !exists {
return true
}
}
return showcaller
}
//getDefaultCallerInfoSetting default setting for callerinfo
func (l *CallerInfo) getDefaultCallerInfoSetting() map[callerInfoKey]bool {
return map[callerInfoKey]bool{
{"", api.CRITICAL}: true,
{"", api.ERROR}: true,
{"", api.WARNING}: true,
{"", api.INFO}: true,
{"", api.DEBUG}: true,
}
}