Repository navigation
Closed
Labels
Needs TriageThis issue needs to be investigated by a maintainerenhancementNew feature or requestgood first issueGood for newcomers
Description
Requirements
Flagd currently prints structured logs in json format, when running flagd in the console this can cause the logs to be difficult to read.
the zap logger zap.Config struct contains the field Encoding which when set to console instead of json updates the logging structure as follows:
json
{"level":"info","ts":1671548378.306176,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey headerColor (config/samples/example_flags.json)","component":"runtime"}
{"level":"info","ts":1671548378.3061912,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey myBoolFlag (config/samples/example_flags.json)","component":"runtime"}
{"level":"info","ts":1671548378.306196,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey myStringFlag (config/samples/example_flags.json)","component":"runtime"}
{"level":"info","ts":1671548378.306199,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey myFloatFlag (config/samples/example_flags.json)","component":"runtime"}
{"level":"info","ts":1671548378.3062022,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey myIntFlag (config/samples/example_flags.json)","component":"runtime"}
console
1.671549411055416e+09 info runtime/runtime.go:84 configuration change (write) for flagKey myFloatFlag (config/samples/example_flags.json) {"component": "runtime"}
1.6715494110554419e+09 info runtime/runtime.go:84 configuration change (write) for flagKey myIntFlag (config/samples/example_flags.json) {"component": "runtime"}
1.671549411055447e+09 info runtime/runtime.go:84 configuration change (write) for flagKey myObjectFlag (config/samples/example_flags.json) {"component": "runtime"}
1.671549411055451e+09 info runtime/runtime.go:84 configuration change (write) for flagKey isColorYellow (config/samples/example_flags.json) {"component": "runtime"}
This behaviour should be controlled via a viper flag, e.g. e.g. --log-encoding=console with a json default--log-encoding=json with a console default
Reacted by Michael Beemer and Kavindu Dodanduwa
Metadata
Metadata
Assignees
Labels
Needs TriageThis issue needs to be investigated by a maintainerenhancementNew feature or requestgood first issueGood for newcomers
Activity
mihirm21 commentedon Jan 22, 2023
Hi, can I be assigned this issue in case no one else is working on it, or should I directly submit my PR?
Update logger.go
update logger.go
mihirm21 commentedon Jan 22, 2023
Is the issue resolved now ?
james-milligan commentedon Jan 25, 2023
Ive requested changes in the PR
#302 (review)
mihirm21 commentedon Jan 25, 2023
are you asking for changes in source files of zap encoder? other than that, I am not getting where to add this feature, plz help
james-milligan commentedon Jan 25, 2023
You can introduce a new cli flag in
cmd/start.go, mirroring one of the other existing flags and setting the default to"console"This flag value can be retrieved with
viper.GetString(YOUR_FLAG_NAME)and passed into the constructor of the zap the logger setting thezap.ConfigEncodingproperty to the value passed on startup.This way we set the default to
consolewhile still allowing for developers to use structured json logging if they require itmihirm21 commentedon Jan 25, 2023
how do I pass this value(viper.GetString(flag name)) to the zap.config encoding parameter
james-milligan commentedon Jan 25, 2023
One option is to update the
NewZapLoggersignature to the following:or
update the
NewZapLoggersignature to the following:and apply the remaining default values within the
NewZapLoggermethod, e.g.start.go:
logger.go:
I am sure there are other options as well if you decide to take a different route
mihirm21 commentedon Jan 26, 2023
Is the issue resolved now?
beeme1mr commentedon Jan 26, 2023
Hi @mihirm21, the issue will automatically be resolved once your PR is accepted and merged. Thanks for your contributions to the project!
chore: rename constructor method (open-feature#237)