7
0
grlogs/log_test.go

99 Zeilen
2.0 KiB
Go

2020-04-01 11:38:28 +08:00
package grlogs
import (
"errors"
2020-05-04 21:10:20 +08:00
_ "golib.gaore.com/GaoreGo/grlogs/logs/alils"
2020-04-28 14:32:56 +08:00
_ "golib.gaore.com/GaoreGo/grlogs/logs/es"
"sync"
2020-04-01 11:38:28 +08:00
"testing"
"time"
2020-04-01 11:38:28 +08:00
)
func TestGetLogger(t *testing.T) {
2020-04-29 11:28:18 +08:00
// 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出
2020-04-28 14:32:56 +08:00
l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch)
l.Debug("我正在调试")
l.Critical("出错了")
2020-04-29 11:28:18 +08:00
// 复用 nds 的日志通道
Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
2020-04-28 15:27:39 +08:00
2020-04-29 11:28:18 +08:00
// 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出
2020-04-28 15:49:04 +08:00
GetEs("wifi")
2020-04-28 15:27:39 +08:00
for i := 0; i < 10; i++ {
2020-04-29 11:28:18 +08:00
Get("wifi").Warning("Warning")
Get("wifi").Warn("Warn")
Get("wifi").Debug("Debug")
Get("wifi").Error("Error")
Get("wifi").Notice("Notice")
Get("wifi").Info("Info")
Get("wifi").Alert("Alert")
2020-04-28 15:27:39 +08:00
}
2020-04-29 11:28:18 +08:00
Get("wifi").Critical("neoweiwoewe")
2020-04-01 11:38:28 +08:00
}
2020-04-28 17:17:21 +08:00
2020-05-04 21:10:20 +08:00
func TestGetAliLs(t *testing.T) {
2020-05-05 17:04:08 +08:00
lable := "test_alils"
l := GetAli(lable).Async(128)
2020-05-05 17:04:08 +08:00
for i := 0; i < 2; i++ {
l.Info("Info")
l.Debug("Debug")
l.Warn("Warn")
l.Warning("Warning")
2020-05-05 17:04:08 +08:00
l.Error("Error")
l.Error("Error\n\n 测试换行")
2020-05-05 17:04:08 +08:00
l.Warn("Warn")
}
2020-05-07 10:59:16 +08:00
time.Sleep(time.Hour * 1)
2020-04-28 17:17:21 +08:00
}
func TestDropAdapter(t *testing.T) {
SetAdapter(LevelAll, AdapterAliLs)
DropAdapter(AdapterAliLs)
Informational(errors.New("he hello"))
SetAdapter(LevelAll, AdapterAliLs)
Debug(errors.New("he hello"))
CloseAll()
}
2020-05-15 18:33:47 +08:00
func TestNew(t *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
2020-05-15 18:33:47 +08:00
go func(i int) {
GetAli("ok").Debug("%d", i)
time.Sleep(time.Second * 10)
wg.Done()
2020-05-15 18:33:47 +08:00
}(i)
}
for i := 0; i < 10; i++ {
GetAli("ok").Debug("aaaaaa%d", i)
2020-05-15 18:33:47 +08:00
}
wg.Wait()
2020-05-15 18:33:47 +08:00
}
2022-10-28 17:18:50 +08:00
func TestGetEs(t *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
GetEs("ok").Debug("%d", i)
time.Sleep(time.Second * 10)
wg.Done()
}(i)
}
for i := 0; i < 10; i++ {
GetEs("ok").Debug("aaaaaa%d", i)
}
wg.Wait()
}