2019-11-06 02:11:12 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2020-12-31 08:21:31 +00:00
|
|
|
"go.uber.org/zap"
|
2019-11-06 02:11:12 +00:00
|
|
|
"testing"
|
2019-11-07 09:04:36 +00:00
|
|
|
"time"
|
2019-11-06 02:11:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLog(t *testing.T) {
|
|
|
|
Debugf("this is %s message", "debug")
|
|
|
|
Infof("this is %s message", "info")
|
|
|
|
Errorf("this is %s message", "error")
|
|
|
|
// Panicf("this is %s message", "panic")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLogWithConfig(t *testing.T) {
|
2020-12-31 08:21:31 +00:00
|
|
|
config := NewLogConfig()
|
2020-12-31 09:15:40 +00:00
|
|
|
_ = config.Level.Set("debug")
|
2020-12-31 08:21:31 +00:00
|
|
|
config.Name = "main"
|
2020-12-31 09:15:40 +00:00
|
|
|
// config.Fields = []zap.Field{zap.String("traceid", "12123123123")}
|
2019-11-06 02:11:12 +00:00
|
|
|
|
2020-12-31 08:21:31 +00:00
|
|
|
config.Init()
|
|
|
|
|
2020-12-31 09:15:40 +00:00
|
|
|
With("traceid", "21221212122")
|
2019-11-06 02:11:12 +00:00
|
|
|
Debugf("this is %s message", "debug")
|
2020-12-31 08:21:31 +00:00
|
|
|
config.Init()
|
|
|
|
With(zap.String("traceid", "12123123123"))
|
2019-11-06 02:11:12 +00:00
|
|
|
Infof("this is %s message", "info")
|
2020-12-31 09:15:40 +00:00
|
|
|
// Errorf("this is %s message", "error")
|
2019-11-06 02:11:12 +00:00
|
|
|
// Panicf("this is %s message", "panic")
|
|
|
|
}
|
2019-11-07 09:04:36 +00:00
|
|
|
|
|
|
|
func TestLogRote(t *testing.T) {
|
|
|
|
lc := NewLogConfig()
|
|
|
|
lc.MaxSize = 1
|
|
|
|
|
|
|
|
lc.Init()
|
|
|
|
|
|
|
|
for {
|
|
|
|
Infof("this is %s message", "info")
|
2019-11-08 09:45:09 +00:00
|
|
|
time.Sleep(time.Millisecond * 1)
|
2019-11-07 09:04:36 +00:00
|
|
|
}
|
|
|
|
}
|