Browse Source

v1.3.3 暴露两个配置方法

tags/v1.3.5
liangzy 4 years ago
parent
commit
3c03b5c497
4 changed files with 29 additions and 12 deletions
  1. +1
    -1
      log_test.go
  2. +16
    -5
      logs/alils/alils.go
  3. +6
    -6
      logs/alils/callback.go
  4. +6
    -0
      options.go

+ 1
- 1
log_test.go 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) {


+ 16
- 5
logs/alils/alils.go 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
}



+ 6
- 6
logs/alils/callback.go 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())
}

+ 6
- 0
options.go View File

@@ -23,3 +23,9 @@ const (
AdapterElasticSearch Adapter = "es"
AdapterAliLs Adapter = "alils"
)

const (
DEV = "dev"
GRAY = "gray"
PROD = "prod"
)

Loading…
Cancel
Save