@@ -435,6 +435,62 @@ func TestJSONAndTextHandlers(t *testing.T) {
435
435
wantText : `time.mins=3 time.secs=2 msg=message` ,
436
436
wantJSON : `{"time":{"mins":3,"secs":2},"msg":"message"}` ,
437
437
},
438
+ {
439
+ name : "replace empty 1" ,
440
+ with : func (h Handler ) Handler {
441
+ return h .WithGroup ("g" ).WithAttrs ([]Attr {Int ("a" , 1 )})
442
+ },
443
+ replace : func ([]string , Attr ) Attr { return Attr {} },
444
+ attrs : []Attr {Group ("h" , Int ("b" , 2 ))},
445
+ wantText : "" ,
446
+ wantJSON : `{"g":{"h":{}}}` ,
447
+ },
448
+ {
449
+ name : "replace empty 2" ,
450
+ with : func (h Handler ) Handler {
451
+ return h .WithGroup ("g" ).WithAttrs ([]Attr {Int ("a" , 1 )}).WithGroup ("h" ).WithAttrs ([]Attr {Int ("b" , 2 )})
452
+ },
453
+ replace : func ([]string , Attr ) Attr { return Attr {} },
454
+ attrs : []Attr {Group ("i" , Int ("c" , 3 ))},
455
+ wantText : "" ,
456
+ wantJSON : `{"g":{"h":{"i":{}}}}` ,
457
+ },
458
+ {
459
+ name : "replace partial empty attrs 1" ,
460
+ with : func (h Handler ) Handler {
461
+ return h .WithGroup ("g" ).WithAttrs ([]Attr {Int ("a" , 1 )}).WithGroup ("h" ).WithAttrs ([]Attr {Int ("b" , 2 )})
462
+ },
463
+ replace : func (groups []string , attr Attr ) Attr {
464
+ return removeKeys (TimeKey , LevelKey , MessageKey , "a" )(groups , attr )
465
+ },
466
+ attrs : []Attr {Group ("i" , Int ("c" , 3 ))},
467
+ wantText : "g.h.b=2 g.h.i.c=3" ,
468
+ wantJSON : `{"g":{"h":{"b":2,"i":{"c":3}}}}` ,
469
+ },
470
+ {
471
+ name : "replace partial empty attrs 2" ,
472
+ with : func (h Handler ) Handler {
473
+ return h .WithGroup ("g" ).WithAttrs ([]Attr {Int ("a" , 1 )}).WithAttrs ([]Attr {Int ("n" , 4 )}).WithGroup ("h" ).WithAttrs ([]Attr {Int ("b" , 2 )})
474
+ },
475
+ replace : func (groups []string , attr Attr ) Attr {
476
+ return removeKeys (TimeKey , LevelKey , MessageKey , "a" , "b" )(groups , attr )
477
+ },
478
+ attrs : []Attr {Group ("i" , Int ("c" , 3 ))},
479
+ wantText : "g.n=4 g.h.i.c=3" ,
480
+ wantJSON : `{"g":{"n":4,"h":{"i":{"c":3}}}}` ,
481
+ },
482
+ {
483
+ name : "replace partial empty attrs 3" ,
484
+ with : func (h Handler ) Handler {
485
+ return h .WithGroup ("g" ).WithAttrs ([]Attr {Int ("x" , 0 )}).WithAttrs ([]Attr {Int ("a" , 1 )}).WithAttrs ([]Attr {Int ("n" , 4 )}).WithGroup ("h" ).WithAttrs ([]Attr {Int ("b" , 2 )})
486
+ },
487
+ replace : func (groups []string , attr Attr ) Attr {
488
+ return removeKeys (TimeKey , LevelKey , MessageKey , "a" , "c" )(groups , attr )
489
+ },
490
+ attrs : []Attr {Group ("i" , Int ("c" , 3 ))},
491
+ wantText : "g.x=0 g.n=4 g.h.b=2" ,
492
+ wantJSON : `{"g":{"x":0,"n":4,"h":{"b":2,"i":{}}}}` ,
493
+ },
438
494
} {
439
495
r := NewRecord (testTime , LevelInfo , "message" , callerPC (2 ))
440
496
line := strconv .Itoa (r .source ().Line )
0 commit comments