-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Changed log.info to tidy up using fmt.sprintf #2246
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 11 commits
86981e0
894f3cf
9b9bce9
3d06649
2fed3b3
d34bf29
681e441
bd4d60a
d3870fd
c0d9b5a
cc4ef7c
e2fc799
fa18fa6
155020f
24d80f5
10fae31
59819b5
f2c7fd3
d906611
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 |
---|---|---|
|
@@ -272,16 +272,13 @@ func getMaxWorkers(gvk schema.GroupVersionKind, defValue int) int { | |
"_", | ||
-1, | ||
)) | ||
maxWorkers, err := strconv.Atoi(os.Getenv(envVar)) | ||
if err != nil { | ||
// we don't care why we couldn't parse it just use default | ||
log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue) | ||
return defValue | ||
} | ||
|
||
if maxWorkers <= 0 { | ||
log.Info("Value %v not valid. Using default %v", maxWorkers, defValue) | ||
return defValue | ||
maxWorkers := defValue | ||
if val, ok := os.LookupEnv(envVar); ok { | ||
if i, err := strconv.Atoi(val); err != nil { | ||
log.Info(fmt.Sprintf("Unable to find a value for %v. Using default value for maxWorkers %d", envVar, defValue)) | ||
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. I could be wrong, but I think @camilamacedo86 was suggesting that we should log a separate message if we use the default when the environment variable is not set. I would also suggest we follow the structured logging conventions of the logr.Logger. So here, we can use the following since we have encountered an error trying to parse the string as an integer. log.Info("could not parse environment variable as an integer; using default value", "envVar", envVar, "default", defValue) For @camilamacedo86's suggestion, if we do the log.Info("environment variable not set; using default value", "envVar", envVar, "default", defValue) |
||
} else { | ||
maxWorkers = i | ||
} | ||
} | ||
return maxWorkers | ||
} | ||
|
@@ -297,7 +294,7 @@ func getAnsibleVerbosity(gvk schema.GroupVersionKind, defValue int) int { | |
)) | ||
ansibleVerbosity, err := strconv.Atoi(os.Getenv(envVar)) | ||
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. I think we should use the same logic for the ansible verbosity operator. Since the logic is identical, I think it would make sense to define a new function with this signature:
The call it for both |
||
if err != nil { | ||
log.Info("Failed to parse %v from environment. Using default %v", envVar, defValue) | ||
log.Info(fmt.Sprintf("Unable to find a value for %v. Using default value for the ansible verbosity %d", envVar, defValue)) | ||
return defValue | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.