接入阿里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
|
||||
}
|
||||
|
||||
func Close(lable string) {
|
||||
if v, ok := loggers.Load(lable); ok {
|
||||
if tmp, ok := v.(*Logger); ok {
|
||||
tmp.BeeLogger.Close()
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
loggers.Delete(lable)
|
||||
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()
|
||||
}
|
||||
|
17
log_test.go
17
log_test.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user