v1.3.3 暴露两个配置方法

This commit is contained in:
liangzy 2020-05-07 10:59:16 +08:00
parent cd94900f19
commit 3c03b5c497
4 changed files with 29 additions and 12 deletions

View File

@ -48,7 +48,7 @@ func TestGetAliLs(t *testing.T) {
l.Warn("Warn")
}
Close(lable, lable, lable)
time.Sleep(time.Hour * 1)
}
func TestDropAdapter(t *testing.T) {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/aliyun/aliyun-log-go-sdk/producer"
"golib.gaore.com/GaoreGo/grlogs/logs"
"runtime"
"time"
)
@ -40,7 +41,10 @@ func (a *alilsLogger) Init(jsonconfig string) error {
producerConfig.AccessKeyID = a.KeyID
producerConfig.AccessKeySecret = a.KeySecret
producerConfig.LingerMs = 100
producerConfig.AllowLogLevel = "error"
producerConfig.NoRetryStatusCodeList = []int{-1}
producerConfig.Retries = 2
producerConfig.AllowLogLevel = "err"
producerConfig.MaxIoWorkerCount = int64(runtime.NumCPU())
a.producer = producer.InitProducer(producerConfig)
a.callback = &Callback{}
a.producer.Start()
@ -62,12 +66,19 @@ func (a *alilsLogger) WriteMsg(when time.Time, msg string, level int, lable stri
log := producer.GenerateLog(uint32(when.Unix()), vals)
for _, topic := range a.Topics {
if err := a.producer.SendLog(a.Project, a.LogStore, topic, a.Source, log); err != nil {
return err
if env == "dev" || env == "test" {
for _, topic := range a.Topics {
if err := a.producer.SendLogWithCallBack(a.Project, a.LogStore, topic, a.Source, log, a.callback); err != nil {
return err
}
}
} else {
for _, topic := range a.Topics {
if err := a.producer.SendLog(a.Project, a.LogStore, topic, a.Source, log); err != nil {
return err
}
}
}
return nil
}

View File

@ -16,10 +16,10 @@ func (callback *Callback) Success(result *producer.Result) {
}
func (callback *Callback) Fail(result *producer.Result) {
fmt.Println(result.IsSuccessful())
fmt.Println(result.GetErrorCode())
fmt.Println(result.GetErrorMessage())
fmt.Println(result.GetReservedAttempts())
fmt.Println(result.GetRequestId())
fmt.Println(result.GetTimeStampMs())
fmt.Println("IsSuccessful", result.IsSuccessful())
fmt.Println("GetErrorCode", result.GetErrorCode())
fmt.Println("GetErrorMessage", result.GetErrorMessage())
fmt.Println("GetReservedAttempts", result.GetReservedAttempts())
fmt.Println("GetRequestId", result.GetRequestId())
fmt.Println("GetTimeStampMs", result.GetTimeStampMs())
}

View File

@ -23,3 +23,9 @@ const (
AdapterElasticSearch Adapter = "es"
AdapterAliLs Adapter = "alils"
)
const (
DEV = "dev"
GRAY = "gray"
PROD = "prod"
)