logger: add logger Fields test #46

Merged
vtolstov merged 2 commits from logger into master 2022-01-20 00:36:13 +03:00

View File

@ -11,6 +11,19 @@ import (
"go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/logger"
) )
func TestFields(t *testing.T) {
ctx := context.TODO()
buf := bytes.NewBuffer(nil)
l := NewLogger(logger.WithLevel(logger.TraceLevel), logger.WithOutput(buf))
if err := l.Init(); err != nil {
t.Fatal(err)
}
l.Fields("key", "val").Info(ctx, "message")
if !bytes.Contains(buf.Bytes(), []byte(`key=val`)) {
t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes())
}
}
func TestOutput(t *testing.T) { func TestOutput(t *testing.T) {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
l := NewLogger(logger.WithOutput(buf)) l := NewLogger(logger.WithOutput(buf))