Files
loggerx/loggerx_test.go
T

46 lines
802 B
Go
Raw Normal View History

2024-01-22 18:05:51 +08:00
package loggerx_test
import (
2024-04-15 23:26:55 +08:00
"bytes"
2024-01-22 18:05:51 +08:00
"context"
2024-04-15 23:26:55 +08:00
"fmt"
2024-01-22 18:05:51 +08:00
"testing"
2024-01-23 13:37:51 +08:00
"time"
2024-01-22 18:05:51 +08:00
2024-04-18 12:02:44 +08:00
"github.com/yuninks/loggerx"
2024-01-22 18:05:51 +08:00
)
// func TestMain(m *testing.M) {
// }
func TestLogger(t *testing.T) {
2024-04-15 23:26:55 +08:00
b := bytes.NewBuffer(nil)
l := loggerx.NewLogger(
2024-04-15 23:40:55 +08:00
context.Background(),
2024-04-15 23:26:55 +08:00
loggerx.SetErrorToInfo(),
loggerx.SetExtraDriver(b, Print{}),
2024-05-08 16:33:58 +08:00
loggerx.SetFileSplit(loggerx.FileSplitTimeA),
2024-04-15 23:26:55 +08:00
)
2024-01-22 18:05:51 +08:00
l.Error(context.Background(), "test error")
2024-04-03 21:18:44 +08:00
l.Channel("channel1").Error(context.Background(), "channel1 test error")
l.Channel("channel2").Error(context.Background(), "channel2 test error")
2024-01-23 00:12:08 +08:00
l.Info(context.Background(), "test info")
2024-04-15 23:26:55 +08:00
fmt.Println(b.String())
2024-02-03 01:57:56 +08:00
time.Sleep(time.Second * 5)
2024-01-22 18:05:51 +08:00
}
2024-04-15 23:26:55 +08:00
type Print struct {
}
func (pp Print) Write(p []byte) (n int, err error) {
2024-04-15 23:40:55 +08:00
fmt.Print("ppppppppppppppp", string(p))
2024-04-15 23:26:55 +08:00
return
}