-
Notifications
You must be signed in to change notification settings - Fork 889
feat: Log API requests made by CLI #1615
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
Conversation
Thoughts on 'verbose' for the flag? I assume people will use this during scenarios where you would usually also reach for that flag. |
cli/requestlogging.go
Outdated
displayedStatusCode = strconv.Itoa(response.StatusCode) | ||
} | ||
|
||
_, _ = fmt.Fprintf(lrt.Writer, "%s %s %s\n", request.Method, request.URL.String(), displayedStatusCode) |
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.
I think it could be nice to add something here that clarifies this isn't a webserver access log, and instead an outbound client log.
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.
Good point. I added a sending request:
prefix to make this a bit clearer.
I think a Or in relation to |
} | ||
} | ||
|
||
func (lrt loggingRoundTripper) RoundTrip(request *http.Request) (*http.Response, 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.
Do you want add optionally showing body payloads?
Turns out pflag does support this! I updated it so that |
Seems like it's a bit tricky to format for request/response bodies in a readable way. For now I'm just printing them on a single line with a leading tab to help visually separate them. The body content is unquoted to make it easier to copy and paste. Also, I'm only printing the body if it appears to be plain text (content type of |
@dwahler since this got pushed back, would you mind closing for now until this work get's picked back up? |
Basic support for logging API request URLs, behind a
--log-requests
flag.Sample usage:
Fixes #1565