github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zlog/zlogger_test.go (about) 1 package zlog_test 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 "testing" 8 9 "github.com/sohaha/zlsgo/zlog" 10 ) 11 12 type Report struct { 13 Writer io.Writer 14 } 15 16 func (w *Report) Write(p []byte) (n int, err error) { 17 // Here you can initiate an HTTP request to report an error 18 fmt.Println("Report: ", string(p)) 19 20 return w.Writer.Write(p) 21 } 22 23 func TestCustomWriter(t *testing.T) { 24 w := &Report{ 25 Writer: os.Stderr, 26 } 27 28 l1 := zlog.NewZLog(w, "Custom1", zlog.BitDefault|zlog.BitLongFile, zlog.LogDump, true, 3) 29 l1.Info("Test") 30 31 // or 32 33 l2 := zlog.New("Custom2") 34 l2.ResetWriter(w) 35 l2.Info("Test") 36 }