Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions cns/logger/cnslogger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logger

import (
"encoding/json"
"fmt"
"os"
"sync"
Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 144 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

commentFormatting: put a space between `//` and comment text (gocritic)
var requestString string
if bytes, err := json.Marshal(request); err != nil {

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)

Check failure on line 146 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 137 (govet)
requestString = string(bytes)
} else {
requestString = fmt.Sprintf("Failed to json marshal %s, %+v", err, request)
Copy link

Copilot AI Dec 7, 2024

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.

Suggested change
requestString = fmt.Sprintf("Failed to json marshal %s, %+v", err, request)
requestString = fmt.Sprintf("%+v", request)

Copilot uses AI. Check for mistakes.
}

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)
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)

Check failure on line 170 in cns/logger/cnslogger.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 162 (govet)
responseString = string(bytes)
} else {
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString)
Copy link

Copilot AI Dec 7, 2024

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.

Suggested change
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString)
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, response)

Copilot uses AI. Check for mistakes.
}

var msg string
switch {
case err == nil && returnCode == 0:
msg = fmt.Sprintf("[%s] Sent %T %+v.", tag, response, response)
msg = fmt.Sprintf("[%s] Sent %T %s.", tag, response, responseString)
case err != nil:
msg = fmt.Sprintf("[%s] Code:%s, %+v %s.", tag, returnCode.String(), response, err.Error())
msg = fmt.Sprintf("[%s] Code:%s, %s %s.", tag, returnCode.String(), responseString, err.Error())
default:
msg = fmt.Sprintf("[%s] Code:%s, %+v.", tag, returnCode.String(), response)
msg = fmt.Sprintf("[%s] Code:%s, %s.", tag, returnCode.String(), responseString)
}

c.sendTraceInternal(msg)
Expand All @@ -177,14 +193,28 @@
return
}

var requestString string
if bytes, err := json.Marshal(request); err != nil {

Check failure on line 197 in cns/logger/cnslogger.go

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 189 (govet)
requestString = string(bytes)
} else {
requestString = fmt.Sprintf("Failed to json marshal %s, %+v", err, request)
}

var responseString string
if bytes, err := json.Marshal(response); err != nil {

Check failure on line 204 in cns/logger/cnslogger.go

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

shadow: declaration of "err" shadows declaration at line 189 (govet)
responseString = string(bytes)
} else {
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString)
Copy link

Copilot AI Dec 7, 2024

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.

Suggested change
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, responseString)
responseString = fmt.Sprintf("Failed to json marshal %s, %+v", err, response)

Copilot uses AI. Check for mistakes.
}

var msg string
switch {
case err == nil && returnCode == 0:
msg = fmt.Sprintf("[%s] Sent %T %+v %T %+v.", tag, request, request, response, response)
msg = fmt.Sprintf("[%s] Sent %T %s %T %s.", tag, request, requestString, response, responseString)
case err != nil:
msg = fmt.Sprintf("[%s] Code:%s, %+v, %+v, %s.", tag, returnCode.String(), request, response, err.Error())
msg = fmt.Sprintf("[%s] Code:%s, %s, %s, %s.", tag, returnCode.String(), requestString, responseString, err.Error())
default:
msg = fmt.Sprintf("[%s] Code:%s, %+v, %+v.", tag, returnCode.String(), request, response)
msg = fmt.Sprintf("[%s] Code:%s, %s, %s.", tag, returnCode.String(), requestString, responseString)
}

c.sendTraceInternal(msg)
Expand Down
Loading