cockroachdb / cockroachdb/errors

Implement slog.LogValuer

Abierto
#107 1 comentario 6 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Go
Estrellas
2.5k
Forks
74
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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`

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.