-
-
Notifications
You must be signed in to change notification settings - Fork 644
Reland "Replace log package with fully slog-based system" #8854
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
Draft
aarongable
wants to merge
12
commits into
main
Choose a base branch
from
reland-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.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc4c4cd
Reland "Replace log package with fully slog-based system"
aarongable c95f39e
cert-checker: Restore audit tags on findings and run summary (#8843)
beautifulentropy b857d1c
va: Preserve internal error in CAA check audit line (#8850)
beautifulentropy 1545f8b
web: Log problem details on failed requests (#8840)
beautifulentropy 2bf7941
ra: Restore reason on revocation audit logs (#8841)
beautifulentropy a18d1d2
crl/storer: Include issuerNameID in CRL upload logs (#8845)
beautifulentropy 644f6bc
blog: Document writer concurrency requirement of the audit handler (#…
beautifulentropy 6fe6193
docs: Correct stale logging documentation (#8851)
beautifulentropy 92a55b7
publisher: Log serials in hex (#8844)
beautifulentropy fea684f
blog: Stop mutating caller-owned attr slices (#8847)
beautifulentropy c1ab6e1
admin: Only log fields being changed in dry-run UpdateIncident (#8842)
beautifulentropy 3faa24f
blog: Send syslog messages at severity matching their level (#8849)
beautifulentropy 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,61 @@ | ||
| package blog | ||
|
|
||
| // This file contains helper functions that can be used throughout the boulder | ||
| // code base to ensure that certain commonly-logged values always have the same | ||
| // key name and value type. This prevents situations like sometimes calling the | ||
| // requesting account "requester" or "acct" or "regID"; or sometimes logging the | ||
| // authz ID as an integer and sometimes as a string. | ||
| // | ||
| // Any time we find ourselves logging the same slog.Attr from 3+ files we | ||
| // should consider adding a helper here instead. | ||
| // | ||
| // Note that several other attr keys are reserved and should not be used: | ||
| // - "time": used by the slog package | ||
| // - "level": used by the slog package | ||
| // - "msg": used by the slog package | ||
| // - "source": used by the slog package | ||
| // - "error": used by our blog.Error and blog.AuditError helpers | ||
| // - "audit": used by our blog.AuditError and blog.AuditInfo helpers | ||
|
|
||
| import ( | ||
| "log/slog" | ||
|
|
||
| "github.com/letsencrypt/boulder/identifier" | ||
| ) | ||
|
|
||
| // Acct returns a slog.Attr whose key is "acct" and whose value is the unique | ||
| // numeric ID of the account. | ||
| func Acct(acctID int64) slog.Attr { | ||
| return slog.Int64("acct", acctID) | ||
| } | ||
|
|
||
| // Order returns a slog.Attr whose key is "order" and whose value is the unique | ||
| // numeric ID of the order. | ||
| func Order(orderID int64) slog.Attr { | ||
| return slog.Int64("order", orderID) | ||
| } | ||
|
|
||
| // Authz returns a slog.Attr whose key is "authz" and whose value is the unique | ||
| // numeric ID of the authz. | ||
| func Authz(authzID int64) slog.Attr { | ||
| return slog.Int64("authz", authzID) | ||
| } | ||
|
|
||
| // Serial returns a slog.Attr whose key is "serial" and whose value is the | ||
| // given string. The argument should be hex-encoded. | ||
| func Serial(serial string) slog.Attr { | ||
| return slog.String("serial", serial) | ||
| } | ||
|
|
||
| // Idents returns a slog.Attr whose key is "idents" and whose value is a list | ||
| // of the given identifiers. | ||
| func Idents(idents ...identifier.ACMEIdentifier) slog.Attr { | ||
| return slog.Any("idents", idents) | ||
| } | ||
|
|
||
| // Error returns a slog.Attr whose key is "error" and whose value is the value | ||
| // from err.Error(). This attribute is used automatically by methods that log | ||
| // at the error level, like blog.Logger.AuditError(). | ||
| func Error(err error) slog.Attr { | ||
| return slog.String("error", err.Error()) | ||
| } |
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,89 @@ | ||
| package blog | ||
|
|
||
| import ( | ||
| "errors" | ||
| "log/slog" | ||
| "net/netip" | ||
| "testing" | ||
|
|
||
| "github.com/letsencrypt/boulder/identifier" | ||
| ) | ||
|
|
||
| func TestAttrHelpers(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| got slog.Attr | ||
| wantKey string | ||
| wantVal slog.Value | ||
| }{ | ||
| { | ||
| name: "Acct", | ||
| got: Acct(42), | ||
| wantKey: "acct", | ||
| wantVal: slog.Int64Value(42), | ||
| }, | ||
| { | ||
| name: "Order", | ||
| got: Order(17), | ||
| wantKey: "order", | ||
| wantVal: slog.Int64Value(17), | ||
| }, | ||
| { | ||
| name: "Authz", | ||
| got: Authz(99), | ||
| wantKey: "authz", | ||
| wantVal: slog.Int64Value(99), | ||
| }, | ||
| { | ||
| name: "Serial", | ||
| got: Serial("deadbeef"), | ||
| wantKey: "serial", | ||
| wantVal: slog.StringValue("deadbeef"), | ||
| }, | ||
| { | ||
| name: "Error", | ||
| got: Error(errors.New("boom")), | ||
| wantKey: "error", | ||
| wantVal: slog.StringValue("boom"), | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| if tc.got.Key != tc.wantKey { | ||
| t.Errorf("attr key = %q, want %q", tc.got.Key, tc.wantKey) | ||
| } | ||
| if !tc.got.Value.Equal(tc.wantVal) { | ||
| t.Errorf("attr value = %v, want %v", tc.got.Value, tc.wantVal) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestIdentsAttr(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // This test is separate from the above because the Idents helper accepts | ||
| // a variadic number of arguments. | ||
| attr := Idents(identifier.NewDNS("example.com"), identifier.NewIP(netip.MustParseAddr("12.34.56.78"))) | ||
| if attr.Key != "idents" { | ||
| t.Errorf("attr key = %q, want %q", attr.Key, "idents") | ||
| } | ||
|
|
||
| idents, ok := attr.Value.Any().([]identifier.ACMEIdentifier) | ||
| if !ok { | ||
| t.Fatalf("idents attr value should be a slice of ACMEIdentifier, got %T", attr.Value.Any()) | ||
| } | ||
| if len(idents) != 2 { | ||
| t.Fatalf("got %d idents, want 2", len(idents)) | ||
| } | ||
| if idents[0].Value != "example.com" { | ||
| t.Errorf("idents[0].Value = %q, want %q", idents[0].Value, "example.com") | ||
| } | ||
| if idents[1].Value != "12.34.56.78" { | ||
| t.Errorf("idents[1].Value = %q, want %q", idents[1].Value, "12.34.56.78") | ||
| } | ||
| } |
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.
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.
Do not resolve this comment until given approval by SRE -- this comment blocks merging until resolved.