添加支持更多的文件驱动

This commit is contained in:
Yun
2024-04-15 23:26:55 +08:00
parent cb25b524b8
commit c7acaa5af6
3 changed files with 40 additions and 5 deletions
+18 -1
View File
@@ -1,7 +1,9 @@
package loggerx_test
import (
"bytes"
"context"
"fmt"
"testing"
"time"
@@ -13,7 +15,12 @@ import (
func TestLogger(t *testing.T) {
l := loggerx.NewLogger(loggerx.SetErrorToInfo())
b := bytes.NewBuffer(nil)
l := loggerx.NewLogger(
loggerx.SetErrorToInfo(),
loggerx.SetExtraDriver(b, Print{}),
)
l.Error(context.Background(), "test error")
@@ -22,5 +29,15 @@ func TestLogger(t *testing.T) {
l.Info(context.Background(), "test info")
fmt.Println(b.String())
time.Sleep(time.Second * 5)
}
type Print struct {
}
func (pp Print) Write(p []byte) (n int, err error) {
fmt.Print("ppppppppppppppp",string(p))
return
}