Skip to content

Conversation

@rosecodym
Copy link
Contributor

@rosecodym rosecodym commented Dec 4, 2025

Description:

Counterintuitively, a new sink added to an existing logger will not inherit the existing logger's key-value pairs. This has only caused a problem in practice with respect to a small number of known key-value pairs, so this PR creates a way to add specific key-value pairs to new sinks.

This will supersede #4579.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@rosecodym rosecodym marked this pull request as ready for review December 4, 2025 19:25
@rosecodym rosecodym requested review from a team and mcastorina December 4, 2025 19:25
@trufflesteeeve
Copy link
Contributor

trufflesteeeve commented Dec 5, 2025

Nevermind!

Copy link
Contributor

@trufflesteeeve trufflesteeeve left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

Looks good! Feels kind of kludgey but it works.

Comment on lines +149 to +152
// New key-value pairs cannot be ergonomically added directly to cores. logr has code to do it, but that code is not
// exported. Rather than replicating it ourselves, we indirectly use it by creating a temporary logger for the new
// core, adding the key-value pairs to the temporary logger, and then extracting the temporary logger's modified
// core.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the "non-ergonomic way" you're referring to the Core.With method?

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.

4 participants