Skip to content

Commit

Permalink
make sure parent handler affects child until sethandler is called on …
Browse files Browse the repository at this point in the history
…child
  • Loading branch information
inconshreveable committed Jul 28, 2014
1 parent ba12997 commit da1a931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 13 additions & 0 deletions log15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,16 @@ func TestIndependentSetHandler(t *testing.T) {
t.Fatalf("parent handler affected by child")
}
}

// https://github.com/inconshreveable/log15/issues/16
func TestInheritHandler(t *testing.T) {
t.Parallel()

parent, _, r := testLogger()
child := parent.New()
parent.SetHandler(DiscardHandler())
child.Info("test")
if r.Msg == "test" {
t.Fatalf("child handler affected not affected by parent")
}
}
4 changes: 1 addition & 3 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ func (l *logger) write(msg string, lvl Lvl, ctx []interface{}) {
}

func (l *logger) New(ctx ...interface{}) Logger {
// copy the child's handler
h := *l.h
return &logger{append(l.ctx, normalize(ctx)...), &h}
return &logger{append(l.ctx, normalize(ctx)...), &swapHandler{handler: l.h}}
}

func (l *logger) Debug(msg string, ctx ...interface{}) {
Expand Down

0 comments on commit da1a931

Please sign in to comment.