Commit abfceb5
authored
Replace log package with fully slog-based system (#8606)
Replace our //log package with a new //blog package, based on the go
stdlib's slog (structured logging) library. This makes all of our log
lines uniformly json (or structured text in test envs), for ease of
parsing by systems like clickhouse.
The new package has a very similar API to the old one: new loggers are
built by cmd/shell.go and stored on our various "impl" structs. When we
want to log a line, we call a method with the desired log level. In
fact, the new logger type (blog.Logger) has the same name as the old
one, so most struct definitions and constructor arguments don't even
need to be updated.
The changes come in both how we use the logger, and what its output
looks like.
The most obvious change is that all logging calls now take a context as
their first argument. The blog package provides utilities to store
key-value pairs (slog.Attr) on a context, and the blog.Logger will
extract those attributes from the context and include them in the log
output. This makes it very easy to ensure that all log lines after a
certain point (e.g. after the request has been parsed and we've
identified the user and order in question) include relevant identify
details (e.g. the regID and orderID).
More subtly, we no longer ever log fmt.Sprintf-formatted strings or
large "auditEvent" structs. Instead, all of those fields are either
attached to the context (if relevant to multiple potential log lines) or
included as slog.Attrs in the log call itself. This removes the need for
our old log.Info / log.Infof / log.InfoObject variants: everything is
plain messages and attributes.
As before, all log messages include the log level, the current time, the
program being run, the hostname the program is running on, and several
other universally-relevant details. However, these are now presented as
key-value pairs like any other attribute, rather than as unkeyed tags at
the beginning of the message.
All logs are written as either text (for tests) or json (for production
code), tagged with the `[AUDIT]` tag, and checksummed. This means that
our existing log routing and validation should continue to work
unchanged.
> [!NOTE]
> Notes for reviewers:
> - This is a very large PR. I suggest reviewing it one commit at a time
to keep things reasonable. Each commit in the stack is logically scoped
to a single subdirectory for ease of reviewing. However, don't expect
code to compile or tests to pass at intermediate points in the commit
stack, if you check it out locally.
> - This change removes the stdout/stderr split and level-based
coloration from our non-syslog output. We've decided this is explicitly
desirable for prod, and at least temporarily acceptable for integration
tests.
> - Sometimes we log in-memory structures, like identifiers or
validation records. In the JSON output, this works great: they get
serialized to json. In the text output, this works less great: they get
pushed through `fmt.Sprint("%v")`, which is somewhat readable but rarely
optimal. I'm not aware of any good workarounds for this.
> - One drawback of collecting attributes on the context is that it's
not always obvious to the code reader (or writer) which attributes have
already been added to the context, and therefore don't need to be added
again. In writing this PR, several times I had log output like `acct=123
acct=123` because I'd added the same attribute twice in two different
places. I'm not sure if this is a problem worth solving, or if it is,
what the best approach might be.
> [!WARNING]
> **Open question**: As mentioned above, these logs include universal
information like the program name and hostname. Because syslog adds
similar tags of its own, this may mean that syslog-based production logs
have redundant information in them. Are these attributes useful? Should
we just remove them?
Future work that we may want to do, but is not included in this change:
- gRPC server interceptors to attach the service and method name as
attributes to all incoming contexts
- gRPC client/server interceptors to propagate certain well-known (e.g.
acct, serial) attributes across the gRPC boundary
- restore coloration (or even weirder formatting) to integration test
log output, for ease of local debugging
Fixes #85571 parent f9e80fb commit abfceb5
178 files changed
Lines changed: 2857 additions & 6083 deletions
File tree
- bdns
- blog
- validator
- ca
- cmd
- admin
- bad-key-revoker
- boulder-ca
- boulder-mtca
- boulder-mtpublisher
- boulder-publisher
- boulder-ra
- boulder-sa
- boulder-va
- boulder-wfe2
- cert-checker
- crl-checker
- crl-storer
- crl-updater
- email-exporter
- log-validator
- nonce-service
- remoteva
- reversed-hostname-checker
- sfe
- crl
- storer
- updater
- ctpolicy
- docs
- grpc
- log
- validator
- mtpublisher
- observer
- policy
- publisher
- ratelimits
- ra
- redis
- salesforce
- sa
- sfe
- test
- boulder-tools/flushredis
- certs
- integration
- va
- vendor
- golang.org/x
- sys/plan9
- term
- web
- wfe2
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
229 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
230 | 236 | | |
231 | 237 | | |
232 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
451 | | - | |
| 451 | + | |
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| |||
759 | 759 | | |
760 | 760 | | |
761 | 761 | | |
762 | | - | |
| 762 | + | |
763 | 763 | | |
764 | 764 | | |
765 | 765 | | |
| |||
796 | 796 | | |
797 | 797 | | |
798 | 798 | | |
799 | | - | |
| 799 | + | |
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
| |||
815 | 815 | | |
816 | 816 | | |
817 | 817 | | |
818 | | - | |
| 818 | + | |
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
| |||
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
886 | | - | |
| 886 | + | |
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
| |||
948 | 948 | | |
949 | 949 | | |
950 | 950 | | |
951 | | - | |
| 951 | + | |
952 | 952 | | |
953 | 953 | | |
954 | 954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
0 commit comments