Skip to content
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

Add logging to Hub client #118

Merged
merged 1 commit into from
Nov 13, 2020
Merged

Add logging to Hub client #118

merged 1 commit into from
Nov 13, 2020

Conversation

chris-crone
Copy link
Member

- What I did
Added a visible --verbose flag and a hidden --trace flag to help debugging. I've only added logs to the Hub client for now.

- How to verify it
Note that --trace his hidden in the help

$ ./bin/hub-tool --help
A tool to manage your Docker Hub images

Usage:
  ./bin/hub-tool
  ./bin/hub-tool [command]

Available Commands:
  account     Manage your account
  help        Help about any command
  org         Manage organizations
  repo        Manage repositories
  tag         Manage tags
  token       Manage Personal Access Tokens
  version     Version information about this tool

Flags:
  -h, --help      help for ./bin/hub-tool
      --verbose   Print logs
      --version   Display the version of this tool

Use "./bin/hub-tool [command] --help" for more information about a command.
$ ./bin/hub-tool account info --verbose
DEBU[0000] HTTP GET on: https://hub.docker.com/v2/user/ 
DEBU[0000] HTTP GET on: https://hub.docker.com/api/billing/v4/accounts/7cc20906ae28482e822084af305ae76a/hub-plan 
DEBU[0000] bad status code "403 Forbidden": {"message":"access to the resource is forbidden with personal access token"} 
Error: bad status code "403 Forbidden": access to the resource is forbidden with personal access token
$ /bin/hub-tool account info --trace  
DEBU[0000] HTTP GET on: https://hub.docker.com/v2/user/
...
<lots of raw request data>

Signed-off-by: Chris Crone <christopher.crone@docker.com>
@@ -169,15 +170,19 @@ func (c *Client) doRequest(req *http.Request, reqOps ...RequestOp) ([]byte, erro
if c.Ctx != nil {
req = req.WithContext(c.Ctx)
}
log.Debugf("HTTP %s on: %s", req.Method, req.URL)
log.Tracef("HTTP request: %+v", req)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: %#v should have better formatting

%v the value in a default format when printing structs, the plus flag (%+v) adds field names
%#v a Go-syntax representation of the value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there are annoying things with #v though like it prints pointers instead of values... e.g.:

#v: URL:(*url.URL)(0xc00012a2d0)
+v: URL:https://hub.docker.com/v2/user/

Copy link
Collaborator

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chris-crone chris-crone merged commit 4e52218 into main Nov 13, 2020
@chris-crone chris-crone deleted the logger branch November 13, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants