define types for "structured error"#415
Open
pohly wants to merge 2 commits into
Open
Conversation
ErrorDetailer can be used to extend how error values are logged. klog and zapr will support this interface and other backends might want to do the same, therefore it makes sense to define this interface and the associated convention in logr.
Other logging backends than funcr may want to implement the same kind of support for PseudoStruct, to increase portability and/or because it is useful. For example, klog can render PseudoStruct a bit more nicely than arbitrary structs because klog itself iterates over "fields". Having the type in the main package avoids a dependency on the funcr package. With a type alias this is not a breaking API change in logr.
pohly
commented
Jan 26, 2026
|
|
||
| // PseudoStruct is a list of key-value pairs that gets logged as a struct. | ||
| type PseudoStruct []any | ||
| type PseudoStruct = logr.PseudoStruct |
Contributor
Author
There was a problem hiding this comment.
apidiff flags this as an API change:
- PseudoStruct: changed from PseudoStruct to github.com/go-logr/logr.PseudoStruct
I'm not sure whether this is really a problem. Type aliases are meant to support such refactoring without breaking a Go API.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This corresponds to changes proposed for klog in kubernetes/klog#361 and zapr in go-logr/zapr#56.
We do not strictly need these type definitions in logr, but having them here makes it more likely that different logr backends behave consistently. For that reason the PseudoStruct type should also better be defined in the main package. In addition, it avoids having a funcr dependency in other logging backends when they implement this type.