Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement slog.LogValuer #107

Open
Open
@samber

Description

The new slog library provides a slog.LogValuer interface for formatting attributes.

Documentation here: https://pkg.go.dev/golang.org/x/exp/slog#hdr-Customizing_a_type_s_logging_behavior

I think cockroachdb/errors should implement it.

type customError struct {
 ...
}
func (e customError) Error() string {
 ...
}
// implements slog.LogValuer
func (e customError) LogValue() slog.Value {
	return slog.GroupValue(
	 slog.Int("code", e.code),
	 slog.String("message", e.msg),
	 slog.String("stacktrace", e.stacktrace),
 )
}

slog will be released in go 1.21. But is already available and golang.org/x/exp/slog

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /