-
Notifications
You must be signed in to change notification settings - Fork 12
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
Configuration support for zap logger #52
Configuration support for zap logger #52
Conversation
a692caf
to
9bb1d77
Compare
9bb1d77
to
2cb4548
Compare
2cb4548
to
3f474e2
Compare
Pods in Kubernetes are ephemeral, and we don't use any persistent volumes to backup log files. In case of a Pod restart, the log files will be lost. Best practice is to log directly to STDOUT and STDERR and leave log managament, rotation... to Kubernetes. No reason to keep a log file or manually do rotation. |
It would be nice to add a config option to switch between human-readable logs and JSON logs. |
log/logger.go
Outdated
MaxBackups: maxBackups, | ||
MaxAge: maxAge, | ||
Compress: compress, | ||
Filename: config.LogFilePath, |
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.
check my comment, this is redundant
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.
Updated
log/logger.go
Outdated
logLevel = zap.InfoLevel | ||
) | ||
type LogConfig struct { | ||
LogFilePath 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.
Same for all file-related log config
log/logger.go
Outdated
consoleEncoder := zapcore.NewConsoleEncoder(developmentCfg) | ||
fileEncoder := zapcore.NewJSONEncoder(productionCfg) | ||
var encoder zapcore.Encoder | ||
if config.IsProduction { |
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.
this can be simplified:
encoder = zapcore.NewConsoleEncoder(developmentCfg)
if config.IsProduction {
encoder = zapcore.NewJSONEncoder(productionCfg)
}
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.
I'd rename IsProduction
to UseJSONLogFormat
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.
In that case, can we entirely remove the development
config? And just keep only one configuration. And then according to the log format flag, we can switch the Encoder
config := zap.NewProductionEncoderConfig()
var encoder zapcore.Encoder
encoder = zapcore.NewConsoleEncoder(config)
if config.IsProduction {
encoder = zapcore.NewJSONEncoder(config)
}
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.
that makes sense, I always try to avoid naming something in an application based on environment name and keep things generic
ea16d1e
to
d04494b
Compare
charts/values.yaml
Outdated
log: | ||
# -- Output type of the log, if true, log will be output in json format | ||
useJSONFormat: true |
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.
I guess we could even shorten it to jsonFormat
log/logger.go
Outdated
@@ -10,8 +10,8 @@ import ( | |||
) | |||
|
|||
type LogConfig struct { | |||
UseJSONFormat bool | |||
LogLevel string | |||
JsonFormat bool |
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.
JsonFormat bool | |
JSONFormat bool |
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.
updated
closes #48
Changes:
DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL