cockroachdb / cockroachdb/errors

Implement slog.LogValuer

Aberta
#107 1 comentário 6 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Go
Estrelas
2.5k
Forks
74
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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`

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.