github.com/phuslu/log@v1.0.100/formatter_test.go (about)

     1  package log
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"testing"
     7  )
     8  
     9  func TestFormatterParse(t *testing.T) {
    10  	var jsons = []string{
    11  		`{"time":"2019-07-10T05:35:54.277Z","level":"debug","level":"error","caller":"pretty.go:42","error":"这是一个🌐哦\n","foo":"bar","n":42,"t":true,"f":false,"o":null,"a":[1,2,3],"obj":{"a":[1,2], "b":{"c":3}},"message":"hello json console color writer\t123"}`,
    12  		`{"ts":1234567890,"level":"info","caller":"pretty.go:42","foo":"bad value","foo":"haha","message":"hello self-define time field\t\n"}`,
    13  	}
    14  
    15  	for _, s := range jsons {
    16  		var args FormatterArgs
    17  		parseFormatterArgs([]byte(s), &args)
    18  		t.Logf("%+v", args)
    19  		t.Logf("foo=%v", args.Get("foo"))
    20  	}
    21  }
    22  
    23  func TestFormatterDefault(t *testing.T) {
    24  	DefaultLogger.Writer = &ConsoleWriter{
    25  		Formatter: func(w io.Writer, a *FormatterArgs) (int, error) {
    26  			return fmt.Fprintf(w, "%s\n", a.Message)
    27  		},
    28  	}
    29  
    30  	Info().Msg("aaaa 'b' cccc")
    31  }