|
- package grlogs
-
- import (
- "errors"
- _ "golib.gaore.com/GaoreGo/grlogs/logs/alils"
- _ "golib.gaore.com/GaoreGo/grlogs/logs/es"
- "sync"
- "testing"
- "time"
- )
-
- func TestGetLogger(t *testing.T) {
- // 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出
- l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch)
- l.Debug("我正在调试")
- l.Critical("出错了")
-
- // 复用 nds 的日志通道
- Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
- Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
-
- // 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出
- GetEs("wifi")
- for i := 0; i < 10; i++ {
- 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")
- }
-
- Get("wifi").Critical("neoweiwoewe")
- }
-
- func TestGetAliLs(t *testing.T) {
-
- lable := "test_alils"
- l := GetAli(lable).Async(128)
-
- for i := 0; i < 2; i++ {
- l.Info("Info")
- l.Debug("Debug")
- l.Warn("Warn")
- l.Warning("Warning")
- l.Error("Error")
- l.Error("Error\n\n 测试换行")
- l.Warn("Warn")
- }
-
- time.Sleep(time.Hour * 1)
- }
-
- func TestDropAdapter(t *testing.T) {
- SetAdapter(LevelAll, AdapterAliLs)
- DropAdapter(AdapterAliLs)
- Informational(errors.New("he hello"))
- SetAdapter(LevelAll, AdapterAliLs)
- Debug(errors.New("he hello"))
- CloseAll()
- }
-
- func TestNew(t *testing.T) {
- wg := sync.WaitGroup{}
- for i := 0; i < 10; i++ {
- wg.Add(1)
- go func(i int) {
- GetAli("ok").Debug("%d", i)
- time.Sleep(time.Second * 10)
- wg.Done()
- }(i)
- }
-
- for i := 0; i < 10; i++ {
- GetAli("ok").Debug("aaaaaa%d", i)
- }
-
- wg.Wait()
- }
-
- 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()
- }
|