-
Notifications
You must be signed in to change notification settings - Fork 29
replace klog with zap log. #268
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
Conversation
|
/assign @clyang82 |
aaad376 to
40633ac
Compare
pkg/dispatcher/hash_dispatcher.go
Outdated
| _ = d.consumerSet.Append(toAddConsumers...) | ||
| d.consumerSet.RemoveAll(toRemoveConsumers...) | ||
| log.V(4).Infof("Consumers set for current instance: %s", d.consumerSet.String()) | ||
| log.Infof("Consumers set for current instance: %s", d.consumerSet.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please lower this log level, I missed this in last change :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| // default log level is info | ||
| viper.SetDefault(varLogLevel, "info") | ||
| if err := viper.ReadInConfig(); err != nil { | ||
| if _, ok := err.(*os.PathError); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will the PathError handle the non-existed file path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I did the test of no config file.
cmd/maestro/main.go
Outdated
| viper.SetDefault(varLogLevel, "info") | ||
| if err := viper.ReadInConfig(); err != nil { | ||
| if _, ok := err.(*os.PathError); ok { | ||
| log.Infof("no config file '%s' not found", logConfigFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove redundant not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
pkg/logger/zap.go
Outdated
|
|
||
| // InitLogger initializes the logger with the given environment. | ||
| // Must be called before using the logger. | ||
| func InitLogger(env string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we combine InitLogger and GetLogger into new GetLogger:
| func InitLogger(env string) { | |
| func GetLogger() *zap.SugaredLogger { | |
| if zapLogger == nil { | |
| zapLogLevel = zap.NewAtomicLevel() | |
| zapConfig := zap.NewDevelopmentConfig() | |
| zapConfig.DisableStacktrace = true | |
| zapConfig.Encoding = "console" | |
| if environments.GetEnvironmentStrFromEnv() == "development" { | |
| zapLogLevel.SetLevel(zapcore.DebugLevel) | |
| } else { | |
| zapLogLevel.SetLevel(zapcore.InfoLevel) | |
| } | |
| zapLogLevel.SetLevel(zapcore.InfoLevel) | |
| zapConfig.Level = zapLogLevel | |
| zlog, err := zapConfig.Build() | |
| if err != nil { | |
| panic(err) | |
| } | |
| zapLogger = zlog.Sugar() | |
| } | |
| return zapLogger | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't merge InitLogger and zapLogger because InitLogger is called by the framework before the environment is initialized. GetLogger() is used in every package that needs to log messages. The zapLogger == nil check is necessary because, in unit tests, we don't use the framework, so it doesn't call InitLogger, in that case we initialize the logger in GetLogger().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged InitLogger() and GetLogger() as we discussed offline.
e981b8b to
cc35f3e
Compare
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
1b2740c to
832a5ce
Compare
Signed-off-by: morvencao <[email protected]>
832a5ce to
13cc63c
Compare
|
/ok-to-test |
clyang82
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ref: https://issues.redhat.com/browse/ACM-17785
This PR replaces
klogwithzaplogger. The log levels are:It also allows changing the log level at runtime via a
ConfigMapin themaestronamespace:This allows changing the log level without restarting the maestro pod.