接入阿里sls
This commit is contained in:
parent
27ff5fb3db
commit
5e9f6ee73f
15
funtion.go
15
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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user