-
-
Notifications
You must be signed in to change notification settings - Fork 635
Replace log package with fully slog-based system #8606
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
Open
aarongable
wants to merge
41
commits into
main
Choose a base branch
from
slog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
83525f3
Update go.mod to go1.26
aarongable 8b9b50d
Clean up 'non-constant format string' errors in log package
aarongable 6063069
Create new //blog/ package with very familiar API
aarongable 829f5ce
Update all imports to new package
aarongable 948718f
Update cmd/shell glue to set up new blog-based logger
aarongable ed3a1df
Update //bdns
aarongable db50514
Update //grpc
aarongable 5ba7b45
Update //ca
aarongable ffdf71d
Update //crl
aarongable ff48c6a
Update //ctpolicy
aarongable 8c14058
Update //observer
aarongable 688c1e1
Update //policy
aarongable 3cd8050
Update //publisher
aarongable 5ac99df
Update //ra
aarongable ee20b12
Update //ratelimits
aarongable fe4f565
Update //redis
aarongable 8daf0e4
Update //sa
aarongable 25a7daa
Update //salesforce
aarongable 8df93a3
Update //sfe
aarongable 97dfc5a
Update //test
aarongable 3850d92
Update //va
aarongable 1f0eb22
Update //web
aarongable 0d99f14
Update //wfe2
aarongable f1998f0
Update //cmd/admin
aarongable 9737805
Update //cmd/bad-key-revoker
aarongable ce51552
Update //cmd/nonce-service
aarongable 5401c95
Update //cmd/ standalone tools
aarongable 0412683
Update //log/validator
aarongable e871d95
Enable text output in integration tests
aarongable 2c0f0f2
Remove old log package
aarongable 6a85606
Merge branch main into slog
aarongable 46991b0
Review comments
aarongable f54b72c
Fix remaining unit tests
aarongable 323dfb8
Remove blog/adapters.go; that's back in cmd/shell.go
aarongable 22548ff
Clean up dependency on x/term
aarongable 080c2e6
More review feedback
aarongable cc7c122
More review comments; update documentation
aarongable 7ad1d02
Merge branch main into slog
aarongable 22e4e90
Add unit tests (with help from claude)
aarongable 1347282
Fix log-validator checksum mismatch
aarongable 5f28365
Use bytes.TrimSuffix for checksums
aarongable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package blog | ||
|
|
||
| // This file contains adapters which can be used | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/go-logr/stdr" | ||
| "github.com/go-sql-driver/mysql" | ||
| "github.com/redis/go-redis/v9" | ||
| "go.opentelemetry.io/otel" | ||
| "google.golang.org/grpc/grpclog" | ||
| ) | ||
|
|
||
| func InitAdapters(l Logger) { | ||
| _ = mysql.SetLogger(mysqlLogger{l}) | ||
| grpclog.SetLoggerV2(grpcLogger{l}) | ||
| log.SetOutput(logWriter{l}) | ||
| redis.SetLogger(redisLogger{l}) | ||
| otel.SetLogger(stdr.New(logOutput{l})) | ||
| } | ||
|
|
||
| // mysqlLogger implements the mysql.Logger interface. | ||
| type mysqlLogger struct { | ||
| Logger | ||
| } | ||
|
|
||
| func (l mysqlLogger) Print(v ...any) { | ||
| // The mysql package only uses the logger to output errors. | ||
| l.Error(context.Background(), "mysql error", errors.New(fmt.Sprint(v...))) | ||
| } | ||
|
|
||
| // grpcLogger implements the grpclog.LoggerV2 interface. | ||
| type grpcLogger struct { | ||
| Logger | ||
| } | ||
|
|
||
| // Ensure that fatal logs exit, because we use neither the gRPC default logger | ||
| // nor the stdlib default logger, both of which would call os.Exit(1) for us. | ||
| func (l grpcLogger) Fatal(args ...any) { | ||
| l.Error(args...) | ||
| os.Exit(1) | ||
| } | ||
| func (l grpcLogger) Fatalf(format string, args ...any) { | ||
| l.Errorf(format, args...) | ||
| os.Exit(1) | ||
| } | ||
| func (l grpcLogger) Fatalln(args ...any) { | ||
| l.Errorln(args...) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Pass through all Error level logs. | ||
| func (l grpcLogger) Error(args ...any) { | ||
| l.Logger.Error(context.Background(), "grpc error", errors.New(fmt.Sprint(args...))) | ||
| } | ||
| func (l grpcLogger) Errorf(format string, args ...any) { | ||
| l.Logger.Error(context.Background(), "grpc error", fmt.Errorf(format, args...)) | ||
| } | ||
| func (l grpcLogger) Errorln(args ...any) { | ||
| l.Logger.Error(context.Background(), "grpc error", errors.New(fmt.Sprintln(args...))) | ||
| } | ||
|
|
||
| // Pass through most Warnings, but filter out a few noisy ones. | ||
| func (l grpcLogger) Warning(args ...any) { | ||
| l.Logger.Warn(context.Background(), fmt.Sprint(args...)) | ||
| } | ||
| func (l grpcLogger) Warningf(format string, args ...any) { | ||
| l.Logger.Warn(context.Background(), fmt.Sprintf(format, args...)) | ||
| } | ||
| func (l grpcLogger) Warningln(args ...any) { | ||
| msg := fmt.Sprintln(args...) | ||
| // See https://github.com/letsencrypt/boulder/issues/4628 | ||
| if strings.Contains(msg, `ccResolverWrapper: error parsing service config: no JSON service config provided`) { | ||
| return | ||
| } | ||
| // See https://github.com/letsencrypt/boulder/issues/4379 | ||
| if strings.Contains(msg, `Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"`) { | ||
| return | ||
| } | ||
| // Since we've already formatted the message, just pass through to .Warning() | ||
| l.Logger.Warn(context.Background(), msg) | ||
| } | ||
|
|
||
| // Don't log any INFO-level gRPC stuff. In practice this is all noise, like | ||
| // failed TXT lookups for service discovery (we only use A records). | ||
| func (l grpcLogger) Info(args ...any) {} | ||
| func (l grpcLogger) Infof(format string, args ...any) {} | ||
| func (l grpcLogger) Infoln(args ...any) {} | ||
|
|
||
| // V returns true if the verbosity level is less than the verbosity we want to | ||
| // log at. | ||
| func (l grpcLogger) V(_ int) bool { | ||
| // We always return false. This causes gRPC to not log some things which are | ||
| // only logged conditionally if the logLevel is set below a certain value. | ||
| // TODO: Use the wrapped log.Logger.stdoutLevel and log.Logger.syslogLevel | ||
| // to determine a correct return value here. | ||
| return false | ||
| } | ||
|
|
||
| // redisLogger implements the redis internal.Logging interface. | ||
| type redisLogger struct { | ||
| Logger | ||
| } | ||
|
|
||
| func (rl redisLogger) Printf(ctx context.Context, format string, v ...any) { | ||
| rl.Info(ctx, fmt.Sprintf(format, v...)) | ||
| } | ||
|
|
||
| // logWriter implements the io.Writer interface. | ||
| type logWriter struct { | ||
| Logger | ||
| } | ||
|
|
||
| func (lw logWriter) Write(p []byte) (int, error) { | ||
| // Lines received by logWriter will always have a trailing newline. | ||
| lw.Logger.Info(context.Background(), strings.TrimSuffix(string(p), "\n")) | ||
| return len(p), nil | ||
| } | ||
|
|
||
| // logOutput implements the log.Logger interface's Output method for use with logr | ||
| type logOutput struct { | ||
| Logger | ||
| } | ||
|
|
||
| func (l logOutput) Output(calldepth int, logline string) error { | ||
| l.Logger.Info(context.Background(), logline) | ||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.