接入阿里sls, 增加关闭日志通道
This commit is contained in:
parent
b3a1b78006
commit
1d9b78eb37
27
log.go
27
log.go
@ -86,23 +86,36 @@ func GetAli(label string, channelLens ...int64) (l *Logger) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Close(lable string) {
|
func Close(lables ...string) {
|
||||||
if v, ok := loggers.Load(lable); ok {
|
wg := &sync.WaitGroup{}
|
||||||
if tmp, ok := v.(*Logger); ok {
|
for _, lable := range lables {
|
||||||
tmp.BeeLogger.Close()
|
wg.Add(1)
|
||||||
}
|
go func() {
|
||||||
|
if v, ok := loggers.Load(lable); ok {
|
||||||
|
if tmp, ok := v.(*Logger); ok {
|
||||||
|
loggers.Delete(lable)
|
||||||
|
tmp.BeeLogger.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
loggers.Delete(lable)
|
wg.Wait()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseAll() {
|
func CloseAll() {
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
loggers.Range(func(key, value interface{}) bool {
|
loggers.Range(func(key, value interface{}) bool {
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
if tmp, ok := value.(*Logger); ok {
|
if tmp, ok := value.(*Logger); ok {
|
||||||
tmp.BeeLogger.Close()
|
tmp.BeeLogger.Close()
|
||||||
|
loggers.Delete(key)
|
||||||
}
|
}
|
||||||
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
17
log_test.go
17
log_test.go
@ -34,17 +34,18 @@ func TestGetLogger(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetAliLs(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++ {
|
for i := 0; i < 2; i++ {
|
||||||
l.Info("endport")
|
l.Info("Info")
|
||||||
l.Info("endport")
|
l.Debug("Debug")
|
||||||
l.Info("endport")
|
l.Warn("Warn")
|
||||||
l.Info("endport")
|
l.Warning("Warning")
|
||||||
l.Error("Error")
|
l.Error("Error")
|
||||||
l.Error("Error\n\n Error")
|
l.Error("Error\n\n 测试换行")
|
||||||
l.Warn("Warn")
|
l.Warn("Warn")
|
||||||
}
|
}
|
||||||
|
|
||||||
Close("test_alils")
|
Close(lable, lable, lable)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user