Skip to content

Add lazy slice formatters to slogutil#1028

Merged
brandur merged 1 commit into
masterfrom
brandur-slog-lazy-values
Sep 7, 2025
Merged

Add lazy slice formatters to slogutil#1028
brandur merged 1 commit into
masterfrom
brandur-slog-lazy-values

Conversation

@brandur

@brandur brandur commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

Adds a couple slice helpers to slogutil that implement slog.LogValue
to achieve the effect of formatting slices that are used as values in
slog attributes, but only when we actually need to do so because a slog
log line is being printed. Otherwise, LogValue is never called and we
avoid the associated work and allocations.

@brandur
brandur requested a review from bgentry September 7, 2025 12:36
Adds a couple slice helpers to `slogutil` that implement `slog.LogValue`
to achieve the effect of formatting slices that are used as values in
slog attributes, but only when we actually need to do so because a slog
log line is being printed. Otherwise, `LogValue` is never called and we
avoid the associated work and allocations.
@brandur
brandur force-pushed the brandur-slog-lazy-values branch from c87d166 to 42bc65a Compare September 7, 2025 12:37

@bgentry bgentry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@brandur

brandur commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

Thanks!

@brandur
brandur merged commit 2e097a8 into master Sep 7, 2025
11 checks passed
@brandur
brandur deleted the brandur-slog-lazy-values branch September 7, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants