github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/logger/test_output.go (about) 1 package logger 2 3 import ( 4 "testing" 5 6 "github.com/unicornultrafoundation/go-u2u/log" 7 ) 8 9 // SetTestMode sets test mode. 10 func SetTestMode(t testing.TB) { 11 log.Root().SetHandler( 12 log.CallerStackHandler("%v", TestHandler(t, log.LogfmtFormat()))) 13 } 14 15 // TestHandler writes into test log. 16 func TestHandler(t testing.TB, fmtr log.Format) log.Handler { 17 return log.FuncHandler(func(r *log.Record) error { 18 t.Log(string(fmtr.Format(r))) 19 return nil 20 }) 21 }