-
Notifications
You must be signed in to change notification settings - Fork 1
/
fields_key_spec.go
61 lines (50 loc) · 1.53 KB
/
fields_key_spec.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
package native
import (
"github.com/echocat/slf4g/fields"
)
// DefaultFieldKeysSpec is the default instance of FieldKeysSpec which should
// cover the majority of cases.
var DefaultFieldKeysSpec = &FieldKeysSpecImpl{}
// FieldKeysSpec defines the field keys supported this implementation of slf4g.
//
// It is an extension of the default fields.KeysSpec.
type FieldKeysSpec interface {
fields.KeysSpec
// GetLocation defines the key location information of logged event are
// stored inside. Such as the calling method, ...
GetLocation() string
}
// FieldKeysSpecImpl is a default implementation of FieldKeysSpec.
type FieldKeysSpecImpl struct {
fields.KeysSpecImpl
// Location defines the used key of an location.
// If empty "location" will be used instead.
Location string
}
// GetLocation implements FieldKeysSpec#GetLocation()
func (instance *FieldKeysSpecImpl) GetLocation() string {
if v := instance.Location; v != "" {
return v
}
return "location"
}
// NewFieldKeysSpecFacade creates a facade of FieldKeysSpec using the given
// provider.
func NewFieldKeysSpecFacade(provider func() FieldKeysSpec) FieldKeysSpec {
return &fieldKeysSpecFacade{
KeysSpec: fields.NewKeysSpecFacade(func() fields.KeysSpec {
return provider()
}),
provider: provider,
}
}
type fieldKeysSpecFacade struct {
fields.KeysSpec
provider func() FieldKeysSpec
}
func (instance *fieldKeysSpecFacade) GetLocation() string {
return instance.Unwrap().GetLocation()
}
func (instance *fieldKeysSpecFacade) Unwrap() FieldKeysSpec {
return instance.provider()
}