File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,11 @@ func NewWithConfig(conf Config) (*FluentHook, error) {
67
67
}
68
68
69
69
hook := & FluentHook {
70
- Fluent : fd ,
71
- conf : conf ,
72
- levels : conf .LogLevels ,
70
+ Fluent : fd ,
71
+ conf : conf ,
72
+ levels : conf .LogLevels ,
73
+ ignoreFields : make (map [string ]struct {}),
74
+ filters : make (map [string ]func (interface {}) interface {}),
73
75
}
74
76
// set default values
75
77
if len (hook .levels ) == 0 {
@@ -82,12 +84,13 @@ func NewWithConfig(conf Config) (*FluentHook, error) {
82
84
if conf .DefaultMessageField != "" {
83
85
hook .messageField = conf .DefaultMessageField
84
86
}
85
- if hook . ignoreFields == nil {
86
- hook .ignoreFields = make ( map [ string ] struct {})
87
+ for k , v := range conf . DefaultIgnoreFields {
88
+ hook .ignoreFields [ k ] = v
87
89
}
88
- if hook . filters == nil {
89
- hook .filters = make ( map [ string ] func ( interface {}) interface {})
90
+ for k , v := range conf . DefaultFilters {
91
+ hook .filters [ k ] = v
90
92
}
93
+
91
94
return hook , nil
92
95
}
93
96
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ func TestNewWithConfig(t *testing.T) {
66
66
Host : testHOST ,
67
67
Port : port ,
68
68
DefaultMessageField : "DefaultMessageField" ,
69
+ DefaultIgnoreFields : map [string ]struct {}{"ignored" : {}},
70
+ DefaultFilters : map [string ]func (interface {}) interface {}{
71
+ "filtered" : func (x interface {}) interface {} {
72
+ return x
73
+ },
74
+ },
69
75
}
70
76
hook , err := NewWithConfig (conf )
71
77
switch {
@@ -83,6 +89,10 @@ func TestNewWithConfig(t *testing.T) {
83
89
t .Errorf ("hook.Fluent should not be nil" )
84
90
case hook .messageField != "DefaultMessageField" :
85
91
t .Errorf ("hook.messageField should be DefaultMessageField" )
92
+ case len (hook .ignoreFields ) != len (conf .DefaultIgnoreFields ):
93
+ t .Errorf ("hook.ignoreFields should be same as conf.DefaultIgnoreFields" )
94
+ case len (hook .filters ) != len (conf .DefaultFilters ):
95
+ t .Errorf ("hook.filters should be same as conf.DefaultFilters" )
86
96
}
87
97
}
88
98
You can’t perform that action at this time.
0 commit comments