cockroachdb / cockroachdb/errors

Implement slog.LogValuer

Open
#107 1 comment 6 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.5k
Forks
74
PR merge metrics
No merged PRs in 30d

Description

The new [slog](https://pkg.go.dev/golang.org/x/exp/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.

```go
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`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.