更新alisls 配置

This commit is contained in:
余 欣怀 2023-03-13 19:42:29 +08:00
bovenliggende 8b94a0d256
commit 54fcd232bd
6 gewijzigde bestanden met toevoegingen van 32 en 23 verwijderingen

Bestand weergeven

@ -5,7 +5,7 @@
1. 引入
```
import "golib.gaore.com/GaoreGo/grlogs"
import "golib.gaore.com/GaoreGo/haiwai-grlogs"
```
2. 简单用法
```
@ -29,11 +29,11 @@ export GRLOG_APP_NAME=mkt.gaore.com;
```
还需要额外引入es库完成初始化动作
```go
import _ "golib.gaore.com/GaoreGo/grlogs/logs/es"
import _ "haiwai-grlogs/logs/es"
```
```go
import _ "golib.gaore.com/GaoreGo/grlogs/logs/alils"
import _ "haiwai-grlogs/logs/alils"
```
5. 文件日志会写入到 `./runtime/logs/` 文件夹 **请务必在项目构建阶段创建该目录**
@ -51,7 +51,7 @@ package grlogs
import (
"fmt"
_ "golib.gaore.com/GaoreGo/grlogs/logs/es"
_ "haiwai-grlogs/logs/es"
"testing"
"time"
)

Bestand weergeven

@ -56,23 +56,28 @@ var adatperSetMapper = map[Adapter]func(l *Logger, level Level) error{
}
func GenAliConfig(level Level) *AliLSConfig {
var project string = "gaore-app-logstore"
var project = "gr-go-project"
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"
intranet := os.Getenv("GRLOG_INTERNET") != "public"
if intranet && (os.Getenv(envkey) == "development" || os.Getenv(envkey) == "testing") {
intranet = false
}
if intranet {
endpoint = "cn-hongkong-intranet.log.aliyuncs.com"
} else {
endpoint = "cn-hongkong.log.aliyuncs.com"
}
source := os.Getenv("GRLOG_SOURCE")
c := &AliLSConfig{
Project: project,
Endpoint: endpoint,
KeyID: "LTAI4GCHwcqtrFD4DHRHxR4k",
KeySecret: "Ln19xfVYy6OMlJeF9aBvFl4fhRUKBl",
LogStore: "gaore-app-logstore",
Topics: []string{os.Getenv("GRLOG_APP_NAME")},
Source: "",
KeyID: "LTAI5tMA7iMGFfuc3xSRVCGQ",
KeySecret: "z98EpzmYmgiVLKizxP7pMF4BPbHfPV",
LogStore: os.Getenv("GRLOG_APP_NAME"),
Topics: []string{os.Getenv("GRLOG_TOPIC")},
Source: source,
Level: level,
FlushWhen: 0,
}

8
log.go
Bestand weergeven

@ -2,14 +2,14 @@ package grlogs
import (
"fmt"
"golib.gaore.com/GaoreGo/grlogs/logs"
"haiwai-grlogs/logs"
"os"
"sync"
)
var loggers = sync.Map{}
var envkey = "CENTER_RUNMODE"
var envkey = "GAORE_ENVIRONMENT"
var defaultModeMapping = map[string][]AdapterTupple{
"es": []AdapterTupple{{LevelAll, AdapterConsole}, {LevelAll, AdapterElasticSearch}},
@ -103,7 +103,7 @@ func Close(lables ...string) {
wg := &sync.WaitGroup{}
for _, lable := range lables {
wg.Add(1)
go func() {
go func(lable string) {
if v, ok := loggers.Load(lable); ok {
if tmp, ok := v.(*Logger); ok {
loggers.Delete(lable)
@ -111,7 +111,7 @@ func Close(lables ...string) {
}
}
wg.Done()
}()
}(lable)
}
wg.Wait()

Bestand weergeven

@ -2,8 +2,9 @@ package grlogs
import (
"errors"
_ "golib.gaore.com/GaoreGo/grlogs/logs/alils"
_ "golib.gaore.com/GaoreGo/grlogs/logs/es"
_ "haiwai-grlogs/logs/alils"
_ "haiwai-grlogs/logs/es"
"os"
"sync"
"testing"
"time"
@ -62,12 +63,15 @@ func TestDropAdapter(t *testing.T) {
}
func TestNew(t *testing.T) {
os.Setenv("GRLOG_INTERNET", "public")
os.Setenv("GRLOG_APP_NAME", "yoda.hk")
os.Setenv("GRLOG_ALILS_DEBUG", "on")
t.Log(os.Getenv("GRLOG_INTERNET"))
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
GetAli("ok").Debug("%d", i)
time.Sleep(time.Second * 10)
wg.Done()
}(i)
}

Bestand weergeven

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/aliyun/aliyun-log-go-sdk/producer"
"golib.gaore.com/GaoreGo/grlogs/logs"
"haiwai-grlogs/logs"
"os"
"runtime"
"time"

Bestand weergeven

@ -10,7 +10,7 @@ import (
"time"
"golib.gaore.com/GaoreGo/goes"
"golib.gaore.com/GaoreGo/grlogs/logs"
"haiwai-grlogs/logs"
)
// NewES return a LoggerInterface