Browse Source

[log] proper impl of With for filter

pull/1842/head
Anton Kaliaev 8 years ago
parent
commit
bc6baf6774
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 9 additions and 3 deletions
  1. +1
    -1
      log/filter.go
  2. +8
    -2
      log/filter_test.go

+ 1
- 1
log/filter.go View File

@ -45,7 +45,7 @@ func (l *filter) Error(msg string, keyvals ...interface{}) error {
}
func (l *filter) With(keyvals ...interface{}) Logger {
return l.next.With(keyvals...)
return &filter{next: l.next.With(keyvals...), allowed: l.allowed, errNotAllowed: l.errNotAllowed}
}
// Option sets a parameter for the filter.


+ 8
- 2
log/filter_test.go View File

@ -93,11 +93,17 @@ func TestLevelContext(t *testing.T) {
var logger log.Logger
logger = log.NewTMJSONLogger(&buf)
logger = log.NewFilter(logger, log.AllowAll())
logger = log.NewFilter(logger, log.AllowError())
logger = logger.With("context", "value")
logger.Error("foo", "bar", "baz")
if want, have := `{"_msg":"foo","bar":"baz","context":"value","level":"error"}`, strings.TrimSpace(buf.String()); want != have {
t.Errorf("\nwant '%s'\nhave '%s'", want, have)
}
buf.Reset()
logger.Info("foo", "bar", "baz")
if want, have := `{"_msg":"foo","bar":"baz","context":"value","level":"info"}`, strings.TrimSpace(buf.String()); want != have {
if want, have := ``, strings.TrimSpace(buf.String()); want != have {
t.Errorf("\nwant '%s'\nhave '%s'", want, have)
}
}

Loading…
Cancel
Save