Skip to content

Commit

Permalink
fix a bug where log.Ctx was not expanded + test
Browse files Browse the repository at this point in the history
  • Loading branch information
inconshreveable committed Dec 6, 2014
1 parent 7a18aae commit 9b11652
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions log15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ func TestLogContext(t *testing.T) {
}
}

func TestMapCtx(t *testing.T) {
t.Parallel()

l, _, r := testLogger()
l.Crit("test", Ctx{"foo": "bar"})

if len(r.Ctx) != 2 {
t.Fatalf("Wrong context length, got %d, expected %d", len(r.Ctx), 2)
}

if r.Ctx[0] != "foo" {
t.Fatalf("Wrong context key, got %s expected %s", r.Ctx[0], "foo")
}

if r.Ctx[1] != "bar" {
t.Fatalf("Wrong context value, got %s expected %s", r.Ctx[1], "bar")
}
}

func TestLvlFilterHandler(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
normalizedSuffix := normalize(suffix)
newCtx := make([]interface{}, len(prefix)+len(normalizedSuffix))
n := copy(newCtx, prefix)
copy(newCtx[n:], suffix)
copy(newCtx[n:], normalizedSuffix)
return newCtx
}

Expand Down

0 comments on commit 9b11652

Please sign in to comment.