From 5e9f6ee73f755b8d7f224b9bc2ac081e0016198f Mon Sep 17 00:00:00 2001 From: liangzy Date: Tue, 5 May 2020 16:10:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E9=98=BF=E9=87=8Csls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funtion.go | 15 ++++++++++++--- log_test.go | 3 +++ logs/alils/alils.go | 10 ++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/funtion.go b/funtion.go index 18eb125..bb96022 100644 --- a/funtion.go +++ b/funtion.go @@ -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, diff --git a/log_test.go b/log_test.go index 1497f31..281a930 100644 --- a/log_test.go +++ b/log_test.go @@ -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) } diff --git a/logs/alils/alils.go b/logs/alils/alils.go index bcc7fa0..c79c590 100644 --- a/logs/alils/alils.go +++ b/logs/alils/alils.go @@ -61,8 +61,14 @@ 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) - return err + + 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() {