-
Notifications
You must be signed in to change notification settings - Fork 144
CBG-5109 Fix & vet log *fCtx function arguments #7963
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 |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ | |
|
|
||
| package base | ||
|
|
||
| import "context" | ||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| const cbSGDevModeBuildTagSet = true | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,6 +143,10 @@ func PanicfCtx(ctx context.Context, format string, args ...any) { | |
|
|
||
| // FatalfCtx logs the given formatted string and args to the error log level and given log key and then exits. | ||
| func FatalfCtx(ctx context.Context, format string, args ...any) { | ||
| // no-op call to enable golang.org/x/tools/go/analysis/passes/printf checking in go vet | ||
| if false { | ||
| _ = fmt.Sprintf(format, args...) | ||
| } | ||
| // Fall back to stdlib's log.Panicf if SG loggers aren't set up. | ||
| if errorLogger.Load() == nil { | ||
| log.Fatalf(format, args...) | ||
|
|
@@ -155,16 +159,28 @@ func FatalfCtx(ctx context.Context, format string, args ...any) { | |
|
|
||
| // ErrorfCtx logs the given formatted string and args to the error log level and given log key. | ||
| func ErrorfCtx(ctx context.Context, format string, args ...any) { | ||
| // no-op call to enable golang.org/x/tools/go/analysis/passes/printf checking in go vet | ||
| if false { | ||
| _ = fmt.Sprintf(format, args...) | ||
| } | ||
| logTo(ctx, LevelError, KeyAll, format, args...) | ||
| } | ||
|
|
||
| // WarnfCtx logs the given formatted string and args to the warn log level and given log key. | ||
| func WarnfCtx(ctx context.Context, format string, args ...any) { | ||
| // no-op call to enable golang.org/x/tools/go/analysis/passes/printf checking in go vet | ||
| if false { | ||
| _ = fmt.Sprintf(format, args...) | ||
| } | ||
| logTo(ctx, LevelWarn, KeyAll, format, args...) | ||
| } | ||
|
|
||
| // InfofCtx logs the given formatted string and args to the info log level and given log key. | ||
| func InfofCtx(ctx context.Context, logKey LogKey, format string, args ...any) { | ||
| // no-op call to enable golang.org/x/tools/go/analysis/passes/printf checking in go vet | ||
| if false { | ||
| _ = fmt.Sprintf(format, args...) | ||
| } | ||
| logTo(ctx, LevelInfo, logKey, format, args...) | ||
| } | ||
|
|
||
|
|
@@ -193,6 +209,10 @@ func RecordStats(statsJson string) { | |
| // logTo is the "core" logging function. All other logging functions (like Debugf(), WarnfCtx(), etc.) end up here. | ||
| // The function will fan out the log to all of the various outputs for them to decide if they should log it or not. | ||
| func logTo(ctx context.Context, logLevel LogLevel, logKey LogKey, format string, args ...any) { | ||
| // no-op call to enable golang.org/x/tools/go/analysis/passes/printf checking in go vet | ||
| if false { | ||
| _ = fmt.Sprintf(format, args...) | ||
| } | ||
|
Comment on lines
+212
to
+215
Member
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. Forcing the check just once here in It greatly reduces the impact of the noise of enabling this check (which I think is extremely valuable) There are still some exceptions, like the
Collaborator
Author
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. Does this work? It didn't work for me because I thought it only checks one layer of functions? I would be happy if you were to play with this (but not too long) because maybe I just missed something.
I did wonder if renaming the functions InfoCtxf or just Infof would fix the problem but that would make backports awful. Though that would align with the naming conventions.
Member
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 tried it locally with just
Collaborator
Author
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. Thanks! I really thought I verified this before but it seems to work fine like this. Adding to TestBucketPool.Fatalf is required because of the |
||
| // Defensive bounds-check for log level. All callers of this function should be within this range. | ||
| if logLevel < LevelNone || logLevel >= levelCount { | ||
| return | ||
|
|
@@ -272,7 +292,7 @@ func LogSyncGatewayVersion(ctx context.Context) { | |
| msg := fmt.Sprintf("==== %s ====", LongVersionString) | ||
|
|
||
| // Log the startup indicator to the stderr. | ||
| ConsolefCtx(ctx, LevelNone, KeyNone, msg) | ||
| ConsolefCtx(ctx, LevelNone, KeyNone, "%s", msg) | ||
|
|
||
| // Log the startup indicator to ALL log files too. | ||
| msg = addPrefixes(msg, ctx, LevelNone, KeyNone) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -667,7 +667,7 @@ func (c *Checkpointer) setRetry(checkpoint *replicationCheckpoint, setFn setChec | |||||
| base.InfofCtx(c.ctx, base.KeyReplicate, "Revision mismatch in setCheckpoint - updated from %q to %q based on existing checkpoint, will retry", checkpoint.Rev, existingCheckpoint.Rev) | ||||||
| checkpoint.Rev = existingCheckpoint.Rev | ||||||
| } else { | ||||||
| base.InfofCtx(c.ctx, base.KeyReplicate, "Revision mismatch in setCheckpoint, and unable to retrieve existing, will retry", getErr) | ||||||
| base.InfofCtx(c.ctx, base.KeyReplicate, "Revision mismatch in setCheckpoint, and unable to retrieve existing, will retry") | ||||||
|
||||||
| base.InfofCtx(c.ctx, base.KeyReplicate, "Revision mismatch in setCheckpoint, and unable to retrieve existing, will retry") | |
| base.InfofCtx(c.ctx, base.KeyReplicate, "Revision mismatch in setCheckpoint, and unable to retrieve existing (%v), will retry", getErr) |
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.
The
feedParamsstructure may contain sensitive connection details that should be redacted. WhileUD()is being used, it's unclear if this adequately protects all sensitive fields within the structure. Consider whetherfeedParamsshould be explicitly redacted or if specific fields should be extracted for logging.