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

把 Boomer 结构体的字段 logger 改成 interface 是否更合适一些呢 #204

Open
alexshopee opened this issue Aug 13, 2024 · 1 comment

Comments

@alexshopee
Copy link

目前 Boomer 结构体的定义如下:

type Boomer struct {
	masterHost  string
	masterPort  int
	mode        Mode
	rateLimiter RateLimiter
	slaveRunner *slaveRunner

	localRunner *localRunner
	spawnCount  int
	spawnRate   float64

	cpuProfileFile     string
	cpuProfileDuration time.Duration

	memoryProfileFile     string
	memoryProfileDuration time.Duration

	outputs []Output

	logger *log.Logger
}

其中 logger 字段是 golang 标准库的 Logger 结构体,这样用户只能传一个初始化 Logger 的变量作为 Boomer 的 log,如果改成 interface,定义类似于:

	Logger interface {
		Debug(msg string, keyvals ...interface{})
		Info(msg string, keyvals ...interface{})
		Warn(msg string, keyvals ...interface{})
		Error(msg string, keyvals ...interface{})
	}

的方式,用户可以更灵活,代价更小地接入业务代码中实际需要的 log 呢,有可能是 zap.Logger 等等,如果用户不指定的话再传给一个默认的 Logger ,也许这个方案更灵活一些呢,目前很多的库都是类似的思路,例如 machinery,temporal 等

@myzhan
Copy link
Owner

myzhan commented Aug 15, 2024

确实,从设计上,这样更灵活。但是当时增加这个 logger,只是为了打印 boomer 内部的一些日志,一般情况下,都不需要日志打印。

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

2 participants