接入阿里sls
This commit is contained in:
parent
4843033fe0
commit
c014aca84b
22
log.go
22
log.go
@ -71,5 +71,25 @@ func GetEs(label string, channelLens ...int64) (l *Logger) {
|
||||
l.SetAdapter(filelevel, AdapterFile).SetAdapter(LevelAll, AdapterConsole).SetAdapter(filelevel, AdapterElasticSearch)
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func Close(lable string) {
|
||||
if v, ok := loggers.Load(lable); ok {
|
||||
if tmp, ok := v.(*Logger); ok {
|
||||
tmp.BeeLogger.Close()
|
||||
}
|
||||
}
|
||||
loggers.Delete(lable)
|
||||
}
|
||||
|
||||
func CloseAll() {
|
||||
loggers.Range(func(key, value interface{}) bool {
|
||||
go func() {
|
||||
if tmp, ok := value.(*Logger); ok {
|
||||
tmp.BeeLogger.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
23
log_test.go
23
log_test.go
@ -33,13 +33,18 @@ func TestGetLogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAliLs(t *testing.T) {
|
||||
l := Get("es").SetAdapter(LevelAll, AdapterAliLs)
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Error("Error")
|
||||
l.Error("Error")
|
||||
l.Warn("Warn")
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
|
||||
l := Get("test_alils").SetAdapter(LevelAll, AdapterAliLs)
|
||||
|
||||
for i := 0; i < 1; i++ {
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Info("endport")
|
||||
l.Error("Error")
|
||||
l.Error("Error\n\n Error")
|
||||
l.Warn("Warn")
|
||||
}
|
||||
|
||||
Close("test_alils")
|
||||
}
|
||||
|
@ -35,12 +35,12 @@ func (a *alilsLogger) Init(jsonconfig string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
producerConfig := producer.GetDefaultProducerConfig()
|
||||
producerConfig.Endpoint = a.Endpoint
|
||||
producerConfig.AccessKeyID = a.KeyID
|
||||
producerConfig.AccessKeySecret = a.KeySecret
|
||||
producerConfig.LingerMs = 100
|
||||
producerConfig.AllowLogLevel = "error"
|
||||
a.producer = producer.InitProducer(producerConfig)
|
||||
a.callback = &Callback{}
|
||||
a.producer.Start()
|
||||
@ -72,8 +72,8 @@ func (a *alilsLogger) WriteMsg(when time.Time, msg string, level int, lable stri
|
||||
}
|
||||
|
||||
func (a *alilsLogger) Destroy() {
|
||||
a.producer.Close(60)
|
||||
a.producer.SafeClose()
|
||||
a.producer.Close(300)
|
||||
}
|
||||
|
||||
func (a *alilsLogger) Flush() {
|
||||
|
Loading…
Reference in New Issue
Block a user