-
Notifications
You must be signed in to change notification settings - Fork 17
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
V-style logging with glog and check errs #18
Conversation
@ewilde PTAL |
It seems the CI is having trouble installing the linter. On my local,
|
if switching to glog is going to be a thing, to discern the action items from the request/response bodies, it would be nice to level them separately. glog.V(1).Infof("[DEBUG] creating bucket %s", bucket.Name)
glog.V(2).Infof("[DEBUG] request: POST %s %#v", "/buckets", data) |
@charleschengxu thank you for the PR, i'm not familiar with @canthefason your comment seems like a good suggestions, @charleschengxu thoughts?
|
return response, fmt.Errorf("Status: %s Error reading %s: %s, reason: %q", | ||
resp.Status, resourceType, resourceName, errorResp.ErrorMessage) | ||
} | ||
|
||
json.Unmarshal(bodyBytes, &response) | ||
if err = json.Unmarshal(bodyBytes, &response); err != nil { |
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.
👍
@@ -52,7 +52,7 @@ func clientConfigure() *Client { | |||
func testPreCheck(t *testing.T) { | |||
skip := os.Getenv("RUNSCOPE_ACC") == "" | |||
if skip { | |||
t.Log("runscope client.go tests require setting RUNSCOPE") | |||
t.Log("runscope client.go tests require setting RUNSCOPE_ACC") |
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.
👍
bucket.go
Outdated
type ListTestsInput struct { | ||
BucketName string | ||
Count int | ||
} | ||
|
||
// ListBuckets lists all buckets for an account | ||
// ListTests lists all buckets for an account |
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.
all buckets for an account/all tests for a bucket
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.
Done
Yes @canthefason has a good point and I added the separate leveling in the latest commit. @ewilde The logging utility change is unlikely to impact existing clients. If command line inputs are not accessible, one could resort to something like |
@charleschengxu @canthefason I've had sometime this morning to look at this. I do have some reservations introducing a logging library dependency to a package. I would like the end-user of the library to be able to pick their own favourite. The list is pretty big! https://awesome-go.com/#logging To that end, I had a go at adding some configuration to allow the end-user to drop in their logging library of choice #19 . What do you think? For you to configure glog, it would probably look something like handler := func(level int, format string, args ...interface{}) {
glog.V(level).Infof("Any custom prefix or not %s", fmt.Sprintf(format, args...))
}
RegisterLogHandlers(handler, handler, handler)
|
@ewilde Thanks for the other PR. Once it is merged, I will rebase from it and register the logging utility. |
4e14e9a
to
7935589
Compare
@ewilde I have removed glog from this PR and kept other patches. PTAL |
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.
Thank you
This PR enables level logging so http requests and responses (often verbose) are only logged when the user asks with
-v
flag. More information about glog can be found https://godoc.org/github.com/golang/glog.Originally, go-runscope uses native go log, which is hard to filter and interleaves with the application logs. There is hacky workaround such as
log.SetOutput(ioutil.Discard)
but that does not play well with clients also using go native log.This PR also add the checks for errors by
ReadAll()
andjson.Unmarshal()
in client.go. The recent commits also fix the Makefile withshell
keywords in front of shell commands, linter issues inbucket.go
, and a typo inclient_test.go
.