-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider_fallback.go
100 lines (79 loc) · 2.14 KB
/
provider_fallback.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package log
import (
"io"
"os"
"github.com/echocat/slf4g/level"
"github.com/echocat/slf4g/fields"
)
// IsFallbackProvider will return true of the given Provider is the fallback
// provider. This usually indicates that currently there is no other
// implementation of slf4g registered.
func IsFallbackProvider(candidate Provider) bool {
for candidate != nil {
if _, ok := candidate.(*fallbackProvider); ok {
return true
}
candidate = UnwrapProvider(candidate)
}
return false
}
type fallbackProvider struct {
cache LoggerCache
level level.Level
out io.Writer
}
var fallbackProviderV = func() *fallbackProvider {
result := &fallbackProvider{
out: os.Stderr,
}
result.cache = NewLoggerCache(result.rootFactory, result.factory)
return result
}()
func (instance *fallbackProvider) rootFactory() Logger {
return instance.factory(fallbackRootLoggerName)
}
func (instance *fallbackProvider) factory(name string) Logger {
cl := &fallbackCoreLogger{
fallbackProvider: instance,
name: name,
}
return NewLogger(cl)
}
func (instance *fallbackProvider) GetName() string {
return "fallback"
}
func (instance *fallbackProvider) GetRootLogger() Logger {
return instance.cache.GetRootLogger()
}
func (instance *fallbackProvider) GetLogger(name string) Logger {
return instance.cache.GetLogger(name)
}
func (instance *fallbackProvider) GetLevel() level.Level {
if v := instance.level; v != 0 {
return v
}
return level.Info
}
func (instance *fallbackProvider) SetLevel(in level.Level) {
instance.level = in
}
func (instance *fallbackProvider) GetAllLevels() level.Levels {
return level.GetProvider().GetLevels()
}
func (instance *fallbackProvider) GetFieldKeysSpec() fields.KeysSpec {
return fallbackFieldKeysSpecV
}
var fallbackFieldKeysSpecV = &fallbackFieldKeysSpec{}
type fallbackFieldKeysSpec struct{}
func (instance *fallbackFieldKeysSpec) GetTimestamp() string {
return "timestamp"
}
func (instance *fallbackFieldKeysSpec) GetMessage() string {
return "message"
}
func (instance *fallbackFieldKeysSpec) GetError() string {
return "error"
}
func (instance *fallbackFieldKeysSpec) GetLogger() string {
return "logger"
}