@@ -42,7 +42,7 @@ func testOutput(t *testing.T, format string) {
42
42
klogr : createLogger ().V (0 ),
43
43
text : "test" ,
44
44
keysAndValues : []interface {}{"akey" , "avalue" },
45
- expectedOutput : ` "msg"="test" "akey"="avalue"
45
+ expectedOutput : `"msg"="test" "akey"="avalue"
46
46
` ,
47
47
expectedKlogOutput : `"test" akey="avalue"
48
48
` ,
@@ -51,25 +51,29 @@ func testOutput(t *testing.T, format string) {
51
51
klogr : createLogger ().V (0 ).WithName ("me" ),
52
52
text : "test" ,
53
53
keysAndValues : []interface {}{"akey" , "avalue" },
54
- expectedOutput : `me "msg"="test" "akey"="avalue"
54
+ // Sorted by keys.
55
+ expectedOutput : `"msg"="test" "akey"="avalue" "logger"="me"
55
56
` ,
56
- expectedKlogOutput : `"me: test" akey="avalue"
57
+ // Not sorted by keys.
58
+ expectedKlogOutput : `"test" logger="me" akey="avalue"
57
59
` ,
58
60
},
59
61
"should log with multiple names and values passed to keysAndValues" : {
60
62
klogr : createLogger ().V (0 ).WithName ("hello" ).WithName ("world" ),
61
63
text : "test" ,
62
64
keysAndValues : []interface {}{"akey" , "avalue" },
63
- expectedOutput : `hello/world "msg"="test" "akey"="avalue"
65
+ // Sorted by keys.
66
+ expectedOutput : `"msg"="test" "akey"="avalue" "logger"="hello.world"
64
67
` ,
65
- expectedKlogOutput : `"hello/world: test" akey="avalue"
68
+ // Not sorted by keys.
69
+ expectedKlogOutput : `"test" logger="hello.world" akey="avalue"
66
70
` ,
67
71
},
68
72
"may print duplicate keys with the same value" : {
69
73
klogr : createLogger ().V (0 ),
70
74
text : "test" ,
71
75
keysAndValues : []interface {}{"akey" , "avalue" , "akey" , "avalue" },
72
- expectedOutput : ` "msg"="test" "akey"="avalue"
76
+ expectedOutput : `"msg"="test" "akey"="avalue"
73
77
` ,
74
78
expectedKlogOutput : `"test" akey="avalue" akey="avalue"
75
79
` ,
@@ -78,7 +82,7 @@ func testOutput(t *testing.T, format string) {
78
82
klogr : createLogger ().V (0 ),
79
83
text : "test" ,
80
84
keysAndValues : []interface {}{"akey" , "avalue" , "akey" , "avalue2" },
81
- expectedOutput : ` "msg"="test" "akey"="avalue2"
85
+ expectedOutput : `"msg"="test" "akey"="avalue2"
82
86
` ,
83
87
expectedKlogOutput : `"test" akey="avalue" akey="avalue2"
84
88
` ,
@@ -87,7 +91,7 @@ func testOutput(t *testing.T, format string) {
87
91
klogr : createLogger ().WithValues ("akey" , "avalue" ),
88
92
text : "test" ,
89
93
keysAndValues : []interface {}{"akey" , "avalue" },
90
- expectedOutput : ` "msg"="test" "akey"="avalue"
94
+ expectedOutput : `"msg"="test" "akey"="avalue"
91
95
` ,
92
96
expectedKlogOutput : `"test" akey="avalue"
93
97
` ,
@@ -96,7 +100,7 @@ func testOutput(t *testing.T, format string) {
96
100
klogr : createLogger ().WithValues ("akey9" , "avalue9" , "akey8" , "avalue8" , "akey1" , "avalue1" ),
97
101
text : "test" ,
98
102
keysAndValues : []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"
100
104
` ,
101
105
expectedKlogOutput : `"test" akey9="avalue9" akey8="avalue8" akey1="avalue1" akey5="avalue5" akey4="avalue4"
102
106
` ,
@@ -105,7 +109,7 @@ func testOutput(t *testing.T, format string) {
105
109
klogr : createLogger ().WithValues ("akey" , "avalue" ),
106
110
text : "test" ,
107
111
keysAndValues : []interface {}{"akey" , "avalue2" },
108
- expectedOutput : ` "msg"="test" "akey"="avalue2"
112
+ expectedOutput : `"msg"="test" "akey"="avalue2"
109
113
` ,
110
114
expectedKlogOutput : `"test" akey="avalue2"
111
115
` ,
@@ -114,7 +118,7 @@ func testOutput(t *testing.T, format string) {
114
118
klogr : createLogger (),
115
119
text : "test" ,
116
120
keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
117
- expectedOutput : ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)"
121
+ expectedOutput : `"msg"="test" "akey"="avalue" "akey2"="(MISSING)"
118
122
` ,
119
123
expectedKlogOutput : `"test" akey="avalue" akey2="(MISSING)"
120
124
` ,
@@ -124,7 +128,7 @@ func testOutput(t *testing.T, format string) {
124
128
text : "test" ,
125
129
keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
126
130
// 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)"
128
132
` ,
129
133
expectedKlogOutput : `"test" keyWithoutValue="(MISSING)" akey="avalue" akey2="(MISSING)"
130
134
` ,
@@ -133,7 +137,7 @@ func testOutput(t *testing.T, format string) {
133
137
klogr : createLogger (),
134
138
text : "test" ,
135
139
keysAndValues : []interface {}{"akey" , "<&>" },
136
- expectedOutput : ` "msg"="test" "akey"="<&>"
140
+ expectedOutput : `"msg"="test" "akey"="<&>"
137
141
` ,
138
142
expectedKlogOutput : `"test" akey="<&>"
139
143
` ,
@@ -143,7 +147,7 @@ func testOutput(t *testing.T, format string) {
143
147
text : "test" ,
144
148
keysAndValues : []interface {}{"akey" , "avalue" , "akey2" },
145
149
// 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)"
147
151
` ,
148
152
expectedKlogOutput : `"test" basekey1="basevar1" basekey2="(MISSING)" akey="avalue" akey2="(MISSING)"
149
153
` ,
@@ -152,7 +156,7 @@ func testOutput(t *testing.T, format string) {
152
156
klogr : createLogger ().V (0 ),
153
157
text : "test" ,
154
158
keysAndValues : []interface {}{"err" , errors .New ("whoops" )},
155
- expectedOutput : ` "msg"="test" "err"="whoops"
159
+ expectedOutput : `"msg"="test" "err"="whoops"
156
160
` ,
157
161
expectedKlogOutput : `"test" err="whoops"
158
162
` ,
@@ -161,7 +165,7 @@ func testOutput(t *testing.T, format string) {
161
165
klogr : createLogger ().V (0 ),
162
166
text : "test" ,
163
167
keysAndValues : []interface {}{"err" , & customErrorJSON {"whoops" }},
164
- expectedOutput : ` "msg"="test" "err"="WHOOPS"
168
+ expectedOutput : `"msg"="test" "err"="WHOOPS"
165
169
` ,
166
170
expectedKlogOutput : `"test" err="whoops"
167
171
` ,
@@ -170,7 +174,7 @@ func testOutput(t *testing.T, format string) {
170
174
klogr : createLogger ().V (0 ),
171
175
text : "test" ,
172
176
err : errors .New ("whoops" ),
173
- expectedOutput : ` "msg"="test" "error"="whoops"
177
+ expectedOutput : `"msg"="test" "error"="whoops"
174
178
` ,
175
179
expectedKlogOutput : `"test" err="whoops"
176
180
` ,
0 commit comments