From 3b1d05dc48c63809e2b54752fd59012f7b63b14f Mon Sep 17 00:00:00 2001 From: Jacky Date: Mon, 14 Oct 2024 23:31:04 +0800 Subject: [PATCH] feat: add custom logger for producer --- producer/logger.go | 6 ++++-- producer/producer_config.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/producer/logger.go b/producer/logger.go index ee0a76a5..2f33bc3b 100644 --- a/producer/logger.go +++ b/producer/logger.go @@ -4,8 +4,8 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "gopkg.in/natefinch/lumberjack.v2" - "os" "io" + "os" ) func logConfig(producerConfig *ProducerConfig) log.Logger { @@ -27,7 +27,9 @@ func logConfig(producerConfig *ProducerConfig) log.Logger { } } var logger log.Logger - if producerConfig.IsJsonType { + if producerConfig.Logger != nil { + logger = producerConfig.Logger + } else if producerConfig.IsJsonType { logger = log.NewJSONLogger(writer) } else { logger = log.NewLogfmtLogger(writer) diff --git a/producer/producer_config.go b/producer/producer_config.go index 706b4414..631e0b2e 100644 --- a/producer/producer_config.go +++ b/producer/producer_config.go @@ -1,6 +1,7 @@ package producer import ( + "github.com/go-kit/kit/log" "net/http" "sync" "time" @@ -58,6 +59,7 @@ type ProducerConfig struct { Region string AuthVersion sls.AuthVersionType CompressType int // only work for logstore now + Logger log.Logger } func GetDefaultProducerConfig() *ProducerConfig {