-
Notifications
You must be signed in to change notification settings - Fork 260
don't dump raw bytes into log output? its hard to read #3249
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| package logger | ||||||
|
|
||||||
| import ( | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "sync" | ||||||
|
|
@@ -140,11 +141,19 @@ | |||||
| return | ||||||
| } | ||||||
|
|
||||||
| //an alternative is to make al request types support stringer/fmt.formatter but thats easy to mess up. | ||||||
|
Check failure on line 144 in cns/logger/cnslogger.go
|
||||||
| var requestString string | ||||||
| if bytes, err := json.Marshal(request); err != nil { | ||||||
|
Check failure on line 146 in cns/logger/cnslogger.go
|
||||||
| requestString = string(bytes) | ||||||
| } else { | ||||||
| requestString = fmt.Sprintf("Failed to json marshal %s, %+v", err, request) | ||||||
| } | ||||||
|
|
||||||
| var msg string | ||||||
| if err == nil { | ||||||
| msg = fmt.Sprintf("[%s] Received %T %+v.", tag, request, request) | ||||||
| msg = fmt.Sprintf("[%s] Received %T %s.", tag, request, requestString) | ||||||
| } else { | ||||||
| msg = fmt.Sprintf("[%s] Failed to decode %T %+v %s.", tag, request, request, err.Error()) | ||||||
| msg = fmt.Sprintf("[%s] Failed to decode %T %s %s.", tag, request, requestString, err.Error()) | ||||||
| } | ||||||
|
|
||||||
| c.sendTraceInternal(msg) | ||||||
|
|
@@ -157,14 +166,21 @@ | |||||
| return | ||||||
| } | ||||||
|
|
||||||
| var responseString string | ||||||
| if bytes, err := json.Marshal(response); err != nil { | ||||||
|
Check failure on line 170 in cns/logger/cnslogger.go
|
||||||
| responseString = string(bytes) | ||||||
| } else { | ||||||
| responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString) | ||||||
|
||||||
| responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString) | |
| responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, response) |
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 197 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.23.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, ubuntu-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Check failure on line 204 in cns/logger/cnslogger.go
GitHub Actions / Lint (1.22.x, windows-latest)
shadow: declaration of "err" shadows declaration at line 189 (govet)
Copilot
AI
Dec 7, 2024
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.
If JSON marshaling fails, the original response object should be included in the log message for debugging purposes.
| responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString) | |
| responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, response) |
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.
If JSON marshaling fails, the original request object should be included in the log message for debugging purposes.