logger: add logger Fields test
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
f4c8a9d18c
commit
37ae3ae741
@ -149,7 +149,7 @@ func (l *zeroLogger) Fields(fields ...interface{}) logger.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) V(level logger.Level) bool {
|
func (l *zeroLogger) V(level logger.Level) bool {
|
||||||
return l.zLog.GetLevel() >= loggerToZerologLevel(level)
|
return l.zLog.GetLevel() <= loggerToZerologLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) Info(ctx context.Context, args ...interface{}) {
|
func (l *zeroLogger) Info(ctx context.Context, args ...interface{}) {
|
||||||
|
@ -12,6 +12,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").Infof(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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user