-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Set glog flags from configuration #3062
Conversation
This PR fixes dgraph-io#2854 Why glog can't use values set in config file? glog reads values from flags. When a user sets the value (of a glog flag) in a config file, glog doesn't recognize it because the flag value hasn't changed. How does this PR fix it? With this PR, we set the value of glog flags from the values in config file. Note: This is a hack. glog doesn't allow setting configuration programatically and thus we have to use this hack. Signed-off-by: Ibrahim Jarif <[email protected]>
@@ -31,7 +31,6 @@ import ( | |||
"github.com/dgraph-io/dgraph/dgraph/cmd/zero" | |||
"github.com/dgraph-io/dgraph/x" | |||
"github.com/spf13/cobra" | |||
flag "github.com/spf13/pflag" |
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.
Aliasing pflag
=> flag
and flag
=> goflag
created unnecessary ambiguity. I've changed this to remove the ambiguity.
Signed-off-by: Ibrahim Jarif <[email protected]>
Signed-off-by: Ibrahim Jarif <[email protected]>
We might also want to evaluate https://github.com/Sirupsen/logrus. It would be much cleaner (and easier) to configure the logging with logrus compared to glog. Also, the logs from glog aren't parseable (you can parse them but searching for a specific key might be difficult). Logrus allows adding context information to logs https://github.com/sirupsen/logrus#default-fields which would be very useful when you have a lof of logs. |
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.
logrus gets really slow because it uses Go maps.
Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @jarifibrahim)
dgraph-io#3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for tracelocation type is set in the config, which is tracelocation{"", 0}. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes dgraph-io#3076 Signed-off-by: Ibrahim Jarif <[email protected]>
dgraph-io#3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for `tracelocation` type is set in the config, which is `tracelocation{"", 0}`. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes dgraph-io#3076 Signed-off-by: Ibrahim Jarif <[email protected]>
dgraph-io#3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for `tracelocation` type is set in the config, which is `tracelocation{"", 0}`. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes dgraph-io#3076 Signed-off-by: Ibrahim Jarif <[email protected]>
#3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for `tracelocation` type is set in the config, which is `tracelocation{"", 0}`. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes #3076 Signed-off-by: Ibrahim Jarif <[email protected]>
* Set glog flags from configuration This PR fixes dgraph-io#2854 Why glog can't use values set in config file? glog reads values from flags. When a user sets the value (of a glog flag) in a config file, glog doesn't recognize it because the flag value hasn't changed. How does this PR fix it? With this PR, we set the value of glog flags from the values in config file. Note: This is a hack. glog doesn't allow setting configuration programatically and thus we have to use this hack. Signed-off-by: Ibrahim Jarif <[email protected]> * Fix error check Signed-off-by: Ibrahim Jarif <[email protected]> * Fix line length Signed-off-by: Ibrahim Jarif <[email protected]>
dgraph-io#3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for `tracelocation` type is set in the config, which is `tracelocation{"", 0}`. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes dgraph-io#3076 Signed-off-by: Ibrahim Jarif <[email protected]>
This PR fixes #2854
Why glog can't use values set in config file?
glog reads values from flags. When a user sets the value (of a glog flag) in a config file, glog doesn't recognize it because the flag value hasn't changed.
How does this PR fix it?
With this PR, we set the value of glog flags from the values in config file.
Note: This is a hack. glog doesn't allow setting configuration programatically and thus we have to use this hack.
Signed-off-by: Ibrahim Jarif [email protected]
This change is