forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
40 lines (33 loc) · 1003 Bytes
/
level.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
/*
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"
//ModuleLevels maintains log levels based on module
type ModuleLevels struct {
levels map[string]api.Level
}
// GetLevel returns the log level for the given module.
func (l *ModuleLevels) GetLevel(module string) api.Level {
level, exists := l.levels[module]
if !exists {
level, exists = l.levels[""]
// no configuration exists, default to info
if !exists {
level = api.INFO
}
}
return level
}
// SetLevel sets the log level for the given module.
func (l *ModuleLevels) SetLevel(module string, level api.Level) {
if l.levels == nil {
l.levels = make(map[string]api.Level)
}
l.levels[module] = level
}
// IsEnabledFor will return true if logging is enabled for the given module.
func (l *ModuleLevels) IsEnabledFor(module string, level api.Level) bool {
return level <= l.GetLevel(module)
}