接入阿里sls, 增加关闭日志通道

This commit is contained in:
liangzy 2020-05-06 11:10:39 +08:00
parent b3a1b78006
commit 1d9b78eb37
2 changed files with 29 additions and 15 deletions

19
log.go
View File

@ -86,23 +86,36 @@ func GetAli(label string, channelLens ...int64) (l *Logger) {
return
}
func Close(lable string) {
func Close(lables ...string) {
wg := &sync.WaitGroup{}
for _, lable := range lables {
wg.Add(1)
go func() {
if v, ok := loggers.Load(lable); ok {
if tmp, ok := v.(*Logger); ok {
loggers.Delete(lable)
tmp.BeeLogger.Close()
}
}
loggers.Delete(lable)
wg.Done()
}()
}
wg.Wait()
}
func CloseAll() {
wg := &sync.WaitGroup{}
loggers.Range(func(key, value interface{}) bool {
wg.Add(1)
go func() {
if tmp, ok := value.(*Logger); ok {
tmp.BeeLogger.Close()
loggers.Delete(key)
}
wg.Done()
}()
return true
})
wg.Wait()
}

View File

@ -34,17 +34,18 @@ func TestGetLogger(t *testing.T) {
func TestGetAliLs(t *testing.T) {
l := GetAli("test_alils")
lable := "test_alils"
l := GetAli(lable).Async(128)
for i := 0; i < 1; i++ {
l.Info("endport")
l.Info("endport")
l.Info("endport")
l.Info("endport")
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 Error")
l.Error("Error\n\n 测试换行")
l.Warn("Warn")
}
Close("test_alils")
Close(lable, lable, lable)
}