@@ -42,7 +42,7 @@ func testOutput(t *testing.T, format string) {
4242klogr : createLogger ().V (0 ),
4343text : "test" ,
4444keysAndValues : []interface {}{"akey" , "avalue" },
45- expectedOutput : ` "msg"="test" "akey"="avalue"
45+ expectedOutput : `"msg"="test" "akey"="avalue"
4646` ,
4747expectedKlogOutput : `"test" akey="avalue"
4848` ,
@@ -51,25 +51,29 @@ func testOutput(t *testing.T, format string) {
5151klogr : createLogger ().V (0 ).WithName ("me" ),
5252text : "test" ,
5353keysAndValues : []interface {}{"akey" , "avalue" },
54- expectedOutput : `me "msg"="test" "akey"="avalue"
54+ // Sorted by keys.
55+ expectedOutput : `"msg"="test" "akey"="avalue" "logger"="me"
5556` ,
56- expectedKlogOutput : `"me: test" akey="avalue"
57+ // Not sorted by keys.
58+ expectedKlogOutput : `"test" logger="me" akey="avalue"
5759` ,
5860},
5961"should log with multiple names and values passed to keysAndValues" : {
6062klogr : createLogger ().V (0 ).WithName ("hello" ).WithName ("world" ),
6163text : "test" ,
6264keysAndValues : []interface {}{"akey" , "avalue" },
63- expectedOutput : `hello/world "msg"="test" "akey"="avalue"
65+ // Sorted by keys.
66+ expectedOutput : `"msg"="test" "akey"="avalue" "logger"="hello.world"
6467` ,
65- expectedKlogOutput : `"hello/world: test" akey="avalue"
68+ // Not sorted by keys.
69+ expectedKlogOutput : `"test" logger="hello.world" akey="avalue"
6670` ,
6771},
6872"may print duplicate keys with the same value" : {
6973klogr : createLogger ().V (0 ),
7074text : "test" ,
7175keysAndValues : []interface {}{"akey" , "avalue" , "akey" , "avalue" },
72- expectedOutput : ` "msg"="test" "akey"="avalue"
76+ expectedOutput : `"msg"="test" "akey"="avalue"
7377` ,
7478expectedKlogOutput : `"test" akey="avalue" akey="avalue"
7579` ,
@@ -78,7 +82,7 @@ func testOutput(t *testing.T, format string) {
7882klogr : createLogger ().V (0 ),
7983text : "test" ,
8084keysAndValues : []interface {}{"akey" , "avalue" , "akey" , "avalue2" },
81- expectedOutput : ` "msg"="test" "akey"="avalue2"
85+ expectedOutput : `"msg"="test" "akey"="avalue2"
8286` ,
8387expectedKlogOutput : `"test" akey="avalue" akey="avalue2"
8488` ,
@@ -87,7 +91,7 @@ func testOutput(t *testing.T, format string) {
8791klogr : createLogger ().WithValues ("akey" , "avalue" ),
8892text : "test" ,
8993keysAndValues : []interface {}{"akey" , "avalue" },
90- expectedOutput : ` "msg"="test" "akey"="avalue"
94+ expectedOutput : `"msg"="test" "akey"="avalue"
9195` ,
9296expectedKlogOutput : `"test" akey="avalue"
9397` ,
@@ -96,7 +100,7 @@ func testOutput(t *testing.T, format string) {
96100klogr : createLogger ().WithValues ("akey9" , "avalue9" , "akey8" , "avalue8" , "akey1" , "avalue1" ),
97101text : "test" ,
98102keysAndValues : []interface {}{"akey5" , "avalue5" , "akey4" , "avalue4" },
99- expectedOutput : ` "msg"="test" "akey1"="avalue1" "akey4"="avalue4" "akey5"="avalue5" "akey8"="avalue8" "akey9"="avalue9"
103+ expectedOutput : `"msg"="test" "akey1"="avalue1" "akey4"="avalue4" "akey5"="avalue5" "akey8"="avalue8" "akey9"="avalue9"
100104` ,
101105expectedKlogOutput : `"test" akey9="avalue9" akey8="avalue8" akey1="avalue1" akey5="avalue5" akey4="avalue4"
102106` ,
@@ -105,7 +109,7 @@ func testOutput(t *testing.T, format string) {
105109klogr : createLogger ().WithValues ("akey" , "avalue" ),
106110text : "test" ,
107111keysAndValues : []interface {}{"akey" , "avalue2" },
108- expectedOutput : ` "msg"="test" "akey"="avalue2"
112+ expectedOutput : `"msg"="test" "akey"="avalue2"
109113` ,
110114expectedKlogOutput : `"test" akey="avalue2"
111115` ,
@@ -114,7 +118,7 @@ func testOutput(t *testing.T, format string) {
114118klogr : createLogger (),
115119text : "test" ,
116120keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
117- expectedOutput : ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)"
121+ expectedOutput : `"msg"="test" "akey"="avalue" "akey2"="(MISSING)"
118122` ,
119123expectedKlogOutput : `"test" akey="avalue" akey2="(MISSING)"
120124` ,
@@ -124,7 +128,7 @@ func testOutput(t *testing.T, format string) {
124128text : "test" ,
125129keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
126130// klogr format sorts all key/value pairs.
127- expectedOutput : ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)" "keyWithoutValue"="(MISSING)"
131+ expectedOutput : `"msg"="test" "akey"="avalue" "akey2"="(MISSING)" "keyWithoutValue"="(MISSING)"
128132` ,
129133expectedKlogOutput : `"test" keyWithoutValue="(MISSING)" akey="avalue" akey2="(MISSING)"
130134` ,
@@ -133,7 +137,7 @@ func testOutput(t *testing.T, format string) {
133137klogr : createLogger (),
134138text : "test" ,
135139keysAndValues : []interface {}{"akey" , "<&>" },
136- expectedOutput : ` "msg"="test" "akey"="<&>"
140+ expectedOutput : `"msg"="test" "akey"="<&>"
137141` ,
138142expectedKlogOutput : `"test" akey="<&>"
139143` ,
@@ -143,7 +147,7 @@ func testOutput(t *testing.T, format string) {
143147text : "test" ,
144148keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
145149// klogr format sorts all key/value pairs.
146- expectedOutput : ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)" "basekey1"="basevar1" "basekey2"="(MISSING)"
150+ expectedOutput : `"msg"="test" "akey"="avalue" "akey2"="(MISSING)" "basekey1"="basevar1" "basekey2"="(MISSING)"
147151` ,
148152expectedKlogOutput : `"test" basekey1="basevar1" basekey2="(MISSING)" akey="avalue" akey2="(MISSING)"
149153` ,
@@ -152,7 +156,7 @@ func testOutput(t *testing.T, format string) {
152156klogr : createLogger ().V (0 ),
153157text : "test" ,
154158keysAndValues : []interface {}{"err" , errors .New ("whoops" )},
155- expectedOutput : ` "msg"="test" "err"="whoops"
159+ expectedOutput : `"msg"="test" "err"="whoops"
156160` ,
157161expectedKlogOutput : `"test" err="whoops"
158162` ,
@@ -161,7 +165,7 @@ func testOutput(t *testing.T, format string) {
161165klogr : createLogger ().V (0 ),
162166text : "test" ,
163167keysAndValues : []interface {}{"err" , & customErrorJSON {"whoops" }},
164- expectedOutput : ` "msg"="test" "err"="WHOOPS"
168+ expectedOutput : `"msg"="test" "err"="WHOOPS"
165169` ,
166170expectedKlogOutput : `"test" err="whoops"
167171` ,
@@ -170,7 +174,7 @@ func testOutput(t *testing.T, format string) {
170174klogr : createLogger ().V (0 ),
171175text : "test" ,
172176err : errors .New ("whoops" ),
173- expectedOutput : ` "msg"="test" "error"="whoops"
177+ expectedOutput : `"msg"="test" "error"="whoops"
174178` ,
175179expectedKlogOutput : `"test" err="whoops"
176180` ,
0 commit comments