chore(message): Add option to redact contents of messages in logs (#719)

This commit is contained in:
Ethan Nguyen
2023-02-20 21:00:24 -06:00
committed by GitHub
parent 131e8a156b
commit a35fc9fbd2
7 changed files with 42 additions and 25 deletions

View File

@@ -33,7 +33,7 @@ type LogPushEntry struct {
var isTerm bool
//nolint
// nolint
func init() {
isTerm = isatty.IsTerminal(os.Stdout.Fd())
}
@@ -175,26 +175,32 @@ func GetLogPushEntry(input *InputLog) LogPushEntry {
token = hideToken(input.Token, 10)
}
message := input.Message
if input.HideMessage {
message = "(message redacted)"
}
return LogPushEntry{
ID: input.ID,
Type: input.Status,
Platform: plat,
Token: token,
Message: input.Message,
Message: message,
Error: errMsg,
}
}
// InputLog log request
type InputLog struct {
ID string
Status string
Token string
Message string
Platform int
Error error
HideToken bool
Format string
ID string
Status string
Token string
Message string
Platform int
Error error
HideToken bool
HideMessage bool
Format string
}
// LogPush record user push request and server response.

View File

@@ -154,6 +154,10 @@ func TestLogPushEntry(t *testing.T) {
in.Token = "1234567890"
in.HideToken = true
assert.Equal(t, "**********", GetLogPushEntry(&in).Token)
in.Message = "hellothisisamessage"
in.HideMessage = true
assert.Equal(t, "(message redacted)", GetLogPushEntry(&in).Message)
}
func TestLogPush(t *testing.T) {