接入阿里sls

This commit is contained in:
liangzy 2020-05-05 16:10:42 +08:00
parent 27ff5fb3db
commit 5e9f6ee73f
3 changed files with 23 additions and 5 deletions

View File

@ -52,13 +52,22 @@ var adatperMapper = map[Adapter]func(l *Logger, level Level) error{
AdapterAliLs: func(l *Logger, level Level) error {
var project string = "gaore-app-logstore"
var endpoint string
if os.Getenv(envkey) == "prod" || os.Getenv(envkey) == "" || os.Getenv(envkey) == "gray" {
endpoint = project + ".cn-shenzhen-intranet.log.aliyuncs.com"
} else if os.Getenv(envkey) == "dev" {
endpoint = project + ".cn-shenzhen.log.aliyuncs.com"
}
c := AliLSConfig{
Project: "gaore-app-logstore",
Endpoint: "gaore-app-logstore.cn-shenzhen.log.aliyuncs.com",
Project: project,
Endpoint: endpoint,
KeyID: "LTAI4GCHwcqtrFD4DHRHxR4k",
KeySecret: "Ln19xfVYy6OMlJeF9aBvFl4fhRUKBl",
LogStore: "gaore-app-logstore",
Topics: nil,
Topics: []string{os.Getenv("GRLOG_APP_NAME")},
Source: "",
Level: level,
FlushWhen: 0,

View File

@ -38,5 +38,8 @@ func TestGetAliLs(t *testing.T) {
l.Info("endport")
l.Info("endport")
l.Info("endport")
l.Error("Error")
l.Error("Error")
l.Warn("Warn")
time.Sleep(time.Millisecond * 500)
}

View File

@ -61,9 +61,15 @@ func (a *alilsLogger) WriteMsg(when time.Time, msg string, level int, lable stri
vals["client_addrs"] = GetCurrentInterfaceAddrs()
log := producer.GenerateLog(uint32(when.Unix()), vals)
err := a.producer.SendLog(a.Project, a.LogStore, "topic", "127.0.0.1", log)
for _, topic := range a.Topics {
if err := a.producer.SendLog(a.Project, a.LogStore, topic, a.Source, log); err != nil {
return err
}
}
return nil
}
func (a *alilsLogger) Destroy() {
a.producer.Close(60)