@@ -169,7 +169,7 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
169
169
k , ok := ctx [i ].(string )
170
170
v := formatLogfmtValue (ctx [i + 1 ], term )
171
171
if ! ok {
172
- k , v = errorKey , formatLogfmtValue ( k , term )
172
+ k , v = errorKey , fmt . Sprintf ( "%+T is not a string key" , ctx [ i ] )
173
173
} else {
174
174
k = escapeString (k )
175
175
}
@@ -218,20 +218,20 @@ func JSONFormatOrderedEx(pretty, lineSeparated bool) Format {
218
218
}
219
219
}
220
220
return FormatFunc (func (r * Record ) []byte {
221
- props := make ( map [string ]interface {})
222
-
223
- props [ r .KeyNames .Time ] = r .Time
224
- props [ r .KeyNames .Lvl ] = r .Lvl . String ()
225
- props [ r . KeyNames . Msg ] = r . Msg
221
+ props := map [string ]interface {}{
222
+ r . KeyNames . Time : r . Time ,
223
+ r .KeyNames .Lvl : r .Lvl . String (),
224
+ r .KeyNames .Msg : r .Msg ,
225
+ }
226
226
227
227
ctx := make ([]string , len (r .Ctx ))
228
228
for i := 0 ; i < len (r .Ctx ); i += 2 {
229
- k , ok := r .Ctx [i ].(string )
230
- if ! ok {
231
- props [errorKey ] = fmt .Sprintf ("%+v is not a string key," , r .Ctx [i ])
229
+ if k , ok := r .Ctx [i ].(string ); ok {
230
+ ctx [i ] = k
231
+ ctx [i + 1 ] = formatLogfmtValue (r .Ctx [i + 1 ], true )
232
+ } else {
233
+ props [errorKey ] = fmt .Sprintf ("%+T is not a string key," , r .Ctx [i ])
232
234
}
233
- ctx [i ] = k
234
- ctx [i + 1 ] = formatLogfmtValue (r .Ctx [i + 1 ], true )
235
235
}
236
236
props [r .KeyNames .Ctx ] = ctx
237
237
@@ -261,18 +261,19 @@ func JSONFormatEx(pretty, lineSeparated bool) Format {
261
261
}
262
262
263
263
return FormatFunc (func (r * Record ) []byte {
264
- props := make ( map [string ]interface {})
265
-
266
- props [ r .KeyNames .Time ] = r .Time
267
- props [ r .KeyNames .Lvl ] = r .Lvl . String ()
268
- props [ r . KeyNames . Msg ] = r . Msg
264
+ props := map [string ]interface {}{
265
+ r . KeyNames . Time : r . Time ,
266
+ r .KeyNames .Lvl : r .Lvl . String (),
267
+ r .KeyNames .Msg : r .Msg ,
268
+ }
269
269
270
270
for i := 0 ; i < len (r .Ctx ); i += 2 {
271
271
k , ok := r .Ctx [i ].(string )
272
272
if ! ok {
273
- props [errorKey ] = fmt .Sprintf ("%+v is not a string key" , r .Ctx [i ])
273
+ props [errorKey ] = fmt .Sprintf ("%+T is not a string key" , r .Ctx [i ])
274
+ } else {
275
+ props [k ] = formatJSONValue (r .Ctx [i + 1 ])
274
276
}
275
- props [k ] = formatJSONValue (r .Ctx [i + 1 ])
276
277
}
277
278
278
279
b , err := jsonMarshal (props )
0 commit comments