Skip to content

Commit

Permalink
Add test for output interceptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
edoger committed Feb 7, 2021
1 parent af7dc11 commit 5857cac
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -638,3 +639,26 @@ func TestLogger_BigLog(t *testing.T) {
t.Fatalf("Big log: %d", n)
}
}

func TestLogger_Interceptor(t *testing.T) {
w1 := new(bytes.Buffer)
o := New("test")
o.SetOutput(w1)
o.SetLevel(TraceLevel)

w2 := new(bytes.Buffer)
interceptor := func(summary Summary, writer io.Writer) (int, error) {
return w2.Write([]byte(summary.Message())) // message only
}
if o.SetOutputInterceptor(interceptor) == nil {
t.Fatal("Logger.SetOutputInterceptor(): nil")
}

o.Echo("foo")
if got := w1.String(); got != "" {
t.Fatalf("Logger.SetOutputInterceptor(): got %s", got)
}
if got := w2.String(); got != "foo" {
t.Fatalf("Logger.SetOutputInterceptor(): got %s", got)
}
}

0 comments on commit 5857cac

Please sign in to comment.