-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Introduce logging level configuration #514
Conversation
cmd/collector/main.go
Outdated
@@ -126,6 +134,7 @@ func main() { | |||
case <-signalsChannel: | |||
logger.Info("Jaeger Collector is finishing") | |||
} | |||
select {} |
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.
why is this needed?
cmd/flags/flags.go
Outdated
@@ -33,7 +33,7 @@ const ( | |||
// ESStorageType is the storage type flag denoting an ElasticSearch backing store | |||
ESStorageType = "elasticsearch" | |||
spanStorageType = "span-storage.type" | |||
logLevel = "log-level" | |||
logLevel = "log-Level" |
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.
shouldn't it be lower case?
cmd/query/main.go
Outdated
@@ -118,6 +126,7 @@ func main() { | |||
case <-serverChannel: | |||
logger.Info("Jaeger Query is finishing") | |||
} | |||
select {} |
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.
?
cmd/flags/flags.go
Outdated
return flags | ||
} | ||
|
||
// AddFlags adds flags for SharedFlags | ||
func AddFlags(flagSet *flag.FlagSet) { | ||
flagSet.String(spanStorageType, CassandraStorageType, fmt.Sprintf("The type of span storage backend to use, options are currently [%v,%v,%v]", CassandraStorageType, ESStorageType, MemoryStorageType)) | ||
flagSet.String(logLevel, "info", "Minimal allowed log level") | ||
flagSet.String(logLevel, "info", "Minimal allowed log Level. For more levels see zap logger documentation") |
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.
instead of zap logger documentation
I'd print the url
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.
added but it looks a bit weird.
Message for conf file:
Configuration file in JSON, TOML, YAML, HCL, or Java properties formats (default none). See spf13/viper for precedence.
cmd/flags/flags.go
Outdated
} | ||
|
||
// NewLogger pareses log Level | ||
func (flags *SharedFlags) NewLogger(conf zap.Config, options ...zap.Option) (*zap.Logger, error) { |
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.
it looks like in all cases you're passing zap.Production() as the config. Is there a use case you're thinking of when it's not going to be production? Also, do we need a way to affect that config from cmd line / our 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.
Is there a use case you're thinking of when it's not going to be production? Also, do we need a way to affect that config from cmd line / our config?
Not right now. Maybe a debug flag or something like that in the future. I made this as flexible as possible.
So do you want to change it to the following?
func (flags *SharedFlags) NewLogger() (*zap.Logger, error)
cmd/flags/flags.go
Outdated
return nil | ||
} | ||
|
||
// NewLogger pareses log Level |
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.
typo "pareses"
|
||
func (co cassandraOptions) ServerList() []string { | ||
return strings.Split(co.Servers, ",") | ||
} |
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.
nice catch
@@ -132,7 +141,8 @@ func main() { | |||
) | |||
|
|||
if error := command.Execute(); error != nil { | |||
logger.Fatal(error.Error()) | |||
fmt.Println(error.Error()) |
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 is unfortunate, because a logger may print the error quite differently, e.g. with a stack trace, write to file, report to Sentry, etc. If we guaranteed that the command only returned errors when it can't init the logger, then it wouldn't be too bad, but I don't think this is generally the case.
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 statement is invoked when:
- an error is propagated from
runE
-> in all cases except logger creation and config file parsingzap.Fatal
is called which directly callsos.exit
. - cobra fails to parse flags e.g. a wrong/undefined flag
Other solution might be to use a default logger here.
e7488af
to
e960dc4
Compare
cmd/flags/flags.go
Outdated
if file := v.GetString(configFile); file != "" { | ||
v.SetConfigFile(file) | ||
err := v.ReadInConfig() | ||
if err != nil { | ||
logger.Fatal("Error loading config file", zap.Error(err), zap.String(configFile, file)) | ||
errors.Wrap(err, fmt.Sprintf("Error loading config file %s", file)) |
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.
missing return
? And you can use Wrapf
for extra formatting.
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.
👍 ouch, the change from log Fatal :)
1c96e3f
to
c6560cb
Compare
@yurishkuro could you please re-review? |
3e0b69e
to
e2295a9
Compare
@pavolloffay could you please rebase from master to make sure all is clean? Then ok to merge. |
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
e2295a9
to
aa7915b
Compare
@yurishkuro thanks, rebased, I will merge on green |
Logging struct was defined in flag package but not used. I have also removed unused code from there.