Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议日志增加可配置不输出日志或者允许传入logger选项 方便输出统一处理 #212

Open
deathbless opened this issue Jun 27, 2023 · 4 comments

Comments

@deathbless
Copy link

type ProducerConfig struct {
	TotalSizeLnBytes      int64
	MaxIoWorkerCount      int64
	MaxBlockSec           int
	MaxBatchSize          int64
	MaxBatchCount         int
	LingerMs              int64
	Retries               int
	MaxReservedAttempts   int
	BaseRetryBackoffMs    int64
	MaxRetryBackoffMs     int64
	AdjustShargHash       bool
	Buckets               int
	AllowLogLevel         string
	LogFileName           string
	IsJsonType            bool
	LogMaxSize            int
	LogMaxBackups         int
	LogCompress           bool
	Endpoint              string
	AccessKeyID           string
	AccessKeySecret       string
	NoRetryStatusCodeList []int
	UpdateStsToken        func() (accessKeyID, accessKeySecret, securityToken string, expireTime time.Time, err error)
	StsTokenShutDown      chan struct{}
	HTTPClient            *http.Client
	UserAgent             string
	NoLog                 bool
}
func logConfig(producerConfig *ProducerConfig) log.Logger {
	var logger log.Logger
	if producerConfig.LogFileName == "" {
		if producerConfig.IsJsonType {
			logger = log.NewJSONLogger(log.NewSyncWriter(os.Stdout))
		} else {
			logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
		}
	} else {
		if producerConfig.IsJsonType {
			logger = log.NewLogfmtLogger(initLogFlusher(producerConfig))
		} else {
			logger = log.NewJSONLogger(initLogFlusher(producerConfig))
		}
	}
	switch producerConfig.AllowLogLevel {
	case "debug":
		logger = level.NewFilter(logger, level.AllowDebug())
	case "info":
		logger = level.NewFilter(logger, level.AllowInfo())
	case "warn":
		logger = level.NewFilter(logger, level.AllowWarn())
	case "error":
		logger = level.NewFilter(logger, level.AllowError())
	default:
		logger = level.NewFilter(logger, level.AllowInfo())
	}
	logger = log.With(logger, "time", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
	if producerConfig.NoLog {
		logger = log.NewNopLogger()
	}
	return logger
}
@wxybear
Copy link

wxybear commented Aug 18, 2023

Sorry 刚才回复错了,是你这边加的nolog,感谢建议,我们考虑下

@wxybear
Copy link

wxybear commented Aug 18, 2023

不过这边我们的worker是个持续运行的过程,如果没有日志无法定位到具体的问题的

@GeekXuan
Copy link

+1,希望支持传入logger

@gpchow
Copy link

gpchow commented Dec 11, 2024

意思是和 consumer 一样,支持传入 Logger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants