Skip to content
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

Log less verbose flags in less verbose modes #837

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func main() {
"uid", os.Getuid(),
"gid", os.Getgid(),
"home", os.Getenv("HOME"),
"flags", logSafeFlags())
"flags", logSafeFlags(*flVerbose))

if _, err := exec.LookPath(*flGitCmd); err != nil {
log.Error(err, "ERROR: git executable not found", "git", *flGitCmd)
Expand Down Expand Up @@ -928,14 +928,19 @@ func redactURL(urlstr string) string {
// logSafeFlags makes sure any sensitive args (e.g. passwords) are redacted
// before logging. This returns a slice rather than a map so it is always
// sorted.
func logSafeFlags() []string {
func logSafeFlags(v int) []string {
ret := []string{}
pflag.VisitAll(func(fl *pflag.Flag) {
// Don't log unchanged values
if !fl.Changed && v <= 3 {
return
}

arg := fl.Name
val := fl.Value.String()

// Don't log empty values
if val == "" {
// Don't log empty, unchanged values
if val == "" && !fl.Changed && v < 6 {
return
}

Expand Down
Loading