replace klog with zap log.#268
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.
Please lower this log level, I missed this in last change :)
| // 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.
will the PathError handle the non-existed file path?
There was a problem hiding this comment.
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) |
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.
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.
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.
merged InitLogger() and GetLogger() as we discussed offline.
e981b8b to
cc35f3e
Compare
Signed-off-by: morvencao <lcao@redhat.com>
1b2740c to
832a5ce
Compare
Signed-off-by: morvencao <lcao@redhat.com>
832a5ce to
13cc63c
Compare
|
/ok-to-test |
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.