-
Notifications
You must be signed in to change notification settings - Fork 713
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
Debug log with concatenated string #128
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,18 +201,18 @@ func addCredentials(c *Client, r *Request) error { | |
func requestLogger(c *Client, r *Request) error { | ||
if c.Debug { | ||
rr := r.RawRequest | ||
c.Log.Println() | ||
c.disableLogPrefix() | ||
c.Log.Println("---------------------- REQUEST LOG -----------------------") | ||
c.Log.Printf("%s %s %s\n", r.Method, rr.URL.RequestURI(), rr.Proto) | ||
c.Log.Printf("HOST : %s", rr.URL.Host) | ||
c.Log.Println("HEADERS:") | ||
reqLog := "\n---------------------- REQUEST LOG -----------------------\n" + | ||
fmt.Sprintf("%s %s %s\n", r.Method, rr.URL.RequestURI(), rr.Proto) + | ||
fmt.Sprintf("HOST : %s\n", rr.URL.Host) + | ||
fmt.Sprintf("HEADERS:\n") | ||
|
||
for h, v := range rr.Header { | ||
c.Log.Printf("%25s: %v", h, strings.Join(v, ", ")) | ||
reqLog += fmt.Sprintf("%25s: %v\n", h, strings.Join(v, ", ")) | ||
} | ||
c.Log.Printf("BODY :\n%v", r.fmtBodyString()) | ||
c.Log.Println("----------------------------------------------------------") | ||
c.enableLogPrefix() | ||
reqLog += fmt.Sprintf("BODY :\n%v\n", r.fmtBodyString()) + | ||
"----------------------------------------------------------\n" | ||
|
||
c.Log.Print(reqLog) | ||
} | ||
|
||
return nil | ||
|
@@ -224,23 +224,23 @@ func requestLogger(c *Client, r *Request) error { | |
|
||
func responseLogger(c *Client, res *Response) error { | ||
if c.Debug { | ||
c.Log.Println() | ||
c.disableLogPrefix() | ||
c.Log.Println("---------------------- RESPONSE LOG -----------------------") | ||
c.Log.Printf("STATUS : %s", res.Status()) | ||
c.Log.Printf("RECEIVED AT : %v", res.ReceivedAt().Format(time.RFC3339Nano)) | ||
c.Log.Printf("RESPONSE TIME : %v", res.Time()) | ||
c.Log.Println("HEADERS:") | ||
resLog := "\n---------------------- RESPONSE LOG -----------------------\n" + | ||
fmt.Sprintf("STATUS : %s\n", res.Status()) + | ||
fmt.Sprintf("RECEIVED AT : %v\n", res.ReceivedAt().Format(time.RFC3339Nano)) + | ||
fmt.Sprintf("RESPONSE TIME : %v\n", res.Time()) + | ||
"HEADERS:\n" | ||
|
||
for h, v := range res.Header() { | ||
c.Log.Printf("%30s: %v", h, strings.Join(v, ", ")) | ||
resLog += fmt.Sprintf("%30s: %v\n", h, strings.Join(v, ", ")) | ||
} | ||
if res.Request.isSaveResponse { | ||
c.Log.Printf("BODY :\n***** RESPONSE WRITTEN INTO FILE *****") | ||
resLog += fmt.Sprintf("BODY :\n***** RESPONSE WRITTEN INTO FILE *****\n") | ||
} else { | ||
c.Log.Printf("BODY :\n%v", res.fmtBodyString(c.debugBodySizeLimit)) | ||
resLog += fmt.Sprintf("BODY :\n%v\n", res.fmtBodyString(c.debugBodySizeLimit)) | ||
} | ||
c.Log.Println("----------------------------------------------------------") | ||
c.enableLogPrefix() | ||
resLog += "----------------------------------------------------------\n" | ||
|
||
c.Log.Print(resLog) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sudo-suhas Please update your code to c.disableLogPrefix()
c.Log.Print(resLog)
c.enableLogPrefix() |
||
} | ||
|
||
return nil | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@sudo-suhas Please update your code to
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.
Could you tell me why you are requesting this change? The output seems correct with the current state from what I can tell. If I do the suggested change, because of concurrent execution, sometimes the prefix is present even though we disabled in the previous line:
debug 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.
@sudo-suhas Okay, I see the prefix is printed in some of the log. Thanks for sharing sample log. This change is not needed. I will look into it later on.