@@ -32,7 +32,6 @@ type testCase struct {
32
32
args []string
33
33
expectedLevels []string
34
34
modules []string
35
- withRegEx bool
36
35
revert bool
37
36
shouldErr bool
38
37
}
@@ -47,38 +46,37 @@ func TestSetModuleLevel(t *testing.T) {
47
46
var tc []testCase
48
47
49
48
tc = append (tc ,
50
- testCase {"Valid" , []string {"a" , "warning" }, []string {"WARNING" }, []string {"a" }, false , false , false },
49
+ testCase {"Valid" , []string {"a" , "warning" }, []string {"WARNING" }, []string {"a" }, false , false },
51
50
// Same as before
52
- testCase {"Invalid" , []string {"a" , "foo" }, []string {"WARNING" }, []string {"a" }, false , false , false },
51
+ testCase {"Invalid" , []string {"a" , "foo" }, []string {flogging .DefaultLevel ()}, []string {"a" }, false , false },
52
+ // Test setting the "error" module
53
+ testCase {"Error" , []string {"error" , "warning" }, []string {"WARNING" }, []string {"error" }, false , false },
53
54
// Tests with regular expressions
54
55
testCase {"RegexModuleWithSubmodule" , []string {"foo" , "warning" }, []string {"WARNING" , "WARNING" , flogging .DefaultLevel ()},
55
- []string {"foo" , "foo/bar" , "baz" }, true , false , false },
56
+ []string {"foo" , "foo/bar" , "baz" }, false , false },
56
57
// Set the level for modules that contain "foo" or "baz"
57
58
testCase {"RegexOr" , []string {"foo|baz" , "debug" }, []string {"DEBUG" , "DEBUG" , "DEBUG" , flogging .DefaultLevel ()},
58
- []string {"foo" , "foo/bar" , "baz" , "random" }, true , false , false },
59
+ []string {"foo" , "foo/bar" , "baz" , "random" }, false , false },
59
60
// Set the level for modules that end with "bar"
60
61
testCase {"RegexSuffix" , []string {"bar$" , "error" }, []string {"ERROR" , flogging .DefaultLevel ()},
61
- []string {"foo/bar" , "bar/baz" }, true , false , false },
62
+ []string {"foo/bar" , "bar/baz" }, false , false },
62
63
testCase {"RegexComplex" , []string {"^[a-z]+\\ /[a-z]+#.+$" , "warning" }, []string {flogging .DefaultLevel (), flogging .DefaultLevel (), "WARNING" , "WARNING" , "WARNING" },
63
- []string {"gossip/util" , "orderer/util" , "gossip/gossip#0.0.0.0:7051" , "gossip/conn#-1" , "orderer/conn#0.0.0.0:7051" }, true , false , false },
64
+ []string {"gossip/util" , "orderer/util" , "gossip/gossip#0.0.0.0:7051" , "gossip/conn#-1" , "orderer/conn#0.0.0.0:7051" }, false , false },
64
65
testCase {"RegexInvalid" , []string {"(" , "warning" }, []string {flogging .DefaultLevel ()},
65
- []string {"foo" }, true , false , true },
66
+ []string {"foo" }, false , true },
66
67
testCase {"RevertLevels" , []string {"revertmodule1" , "warning" , "revertmodule2" , "debug" }, []string {"WARNING" , "DEBUG" , "DEBUG" },
67
- []string {"revertmodule1" , "revertmodule2" , "revertmodule2/submodule" }, true , true , false },
68
+ []string {"revertmodule1" , "revertmodule2" , "revertmodule2/submodule" }, true , false },
68
69
)
69
70
70
71
assert := assert .New (t )
71
72
72
73
for i := 0 ; i < len (tc ); i ++ {
73
74
t .Run (tc [i ].name , func (t * testing.T ) {
74
- if tc [i ].withRegEx {
75
- for j := 0 ; j < len (tc [i ].modules ); j ++ {
76
- flogging .MustGetLogger (tc [i ].modules [j ])
77
- }
78
- if tc [i ].revert {
79
- flogging .SetPeerStartupModulesMap ()
80
- }
81
- flogging .IsSetLevelByRegExpEnabled = true // enable for call below
75
+ for j := 0 ; j < len (tc [i ].modules ); j ++ {
76
+ flogging .MustGetLogger (tc [i ].modules [j ])
77
+ }
78
+ if tc [i ].revert {
79
+ flogging .SetPeerStartupModulesMap ()
82
80
}
83
81
for k := 0 ; k < len (tc [i ].args ); k = k + 2 {
84
82
_ , err := flogging .SetModuleLevel (tc [i ].args [k ], tc [i ].args [k + 1 ])
@@ -95,11 +93,7 @@ func TestSetModuleLevel(t *testing.T) {
95
93
assert .Equal (flogging .GetPeerStartupLevel (tc [i ].modules [m ]), flogging .GetModuleLevel (tc [i ].modules [m ]))
96
94
}
97
95
}
98
- if tc [i ].withRegEx {
99
- // Force reset (a) in case the next test is non-regex, (b) so as
100
- // to reset the modules map and reuse module names.
101
- flogging .Reset ()
102
- }
96
+ flogging .Reset ()
103
97
})
104
98
}
105
99
}
@@ -130,25 +124,25 @@ func TestInitFromSpec(t *testing.T) {
130
124
// MODULES
131
125
132
126
tc = append (tc ,
133
- testCase {"SingleModuleLevel" , []string {"a=info" }, []string {"INFO" }, []string {"a" }, false , false , false },
134
- testCase {"MultipleModulesMultipleLevels" , []string {"a=info:b=debug" }, []string {"INFO" , "DEBUG" }, []string {"a" , "b" }, false , false , false },
135
- testCase {"MultipleModulesSameLevel" , []string {"a,b=warning" }, []string {"WARNING" , "WARNING" }, []string {"a" , "b" }, false , false , false },
127
+ testCase {"SingleModuleLevel" , []string {"a=info" }, []string {"INFO" }, []string {"a" }, false , false },
128
+ testCase {"MultipleModulesMultipleLevels" , []string {"a=info:b=debug" }, []string {"INFO" , "DEBUG" }, []string {"a" , "b" }, false , false },
129
+ testCase {"MultipleModulesSameLevel" , []string {"a,b=warning" }, []string {"WARNING" , "WARNING" }, []string {"a" , "b" }, false , false },
136
130
)
137
131
138
132
// MODULES + DEFAULT
139
133
140
134
tc = append (tc ,
141
- testCase {"GlobalDefaultAndSingleModuleLevel" , []string {"info:a=warning" }, []string {"INFO" , "WARNING" }, []string {"" , "a" }, false , false , false },
142
- testCase {"SingleModuleLevelAndGlobalDefaultAtEnd" , []string {"a=warning:info" }, []string {"WARNING" , "INFO" }, []string {"a" , "" }, false , false , false },
135
+ testCase {"GlobalDefaultAndSingleModuleLevel" , []string {"info:a=warning" }, []string {"INFO" , "WARNING" }, []string {"" , "a" }, false , false },
136
+ testCase {"SingleModuleLevelAndGlobalDefaultAtEnd" , []string {"a=warning:info" }, []string {"WARNING" , "INFO" }, []string {"a" , "" }, false , false },
143
137
)
144
138
145
139
// INVALID INPUT
146
140
147
141
tc = append (tc ,
148
- testCase {"InvalidLevel" , []string {"foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
149
- testCase {"InvalidLevelForSingleModule" , []string {"a=foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
150
- testCase {"EmptyModuleEqualsLevel" , []string {"=warning" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
151
- testCase {"InvalidModuleSyntax" , []string {"a=b=c" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
142
+ testCase {"InvalidLevel" , []string {"foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
143
+ testCase {"InvalidLevelForSingleModule" , []string {"a=foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
144
+ testCase {"EmptyModuleEqualsLevel" , []string {"=warning" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
145
+ testCase {"InvalidModuleSyntax" , []string {"a=b=c" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
152
146
)
153
147
154
148
assert := assert .New (t )
@@ -173,7 +167,7 @@ func ExampleInitBackend() {
173
167
formatSpec := "%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x} %{message}"
174
168
flogging .InitBackend (flogging .SetFormat (formatSpec ), os .Stdout )
175
169
176
- logger := logging .MustGetLogger ("testModule" )
170
+ logger := flogging .MustGetLogger ("testModule" )
177
171
logger .Info ("test output" )
178
172
179
173
// Output:
0 commit comments