cristalhq / bson

BSON for Go
MIT License
3 stars 2 forks source link

Add logging helpers to `bsonproto` #41

Closed AlekSi closed 7 months ago

AlekSi commented 10 months ago
func LogValue[T ScalarType](v T) slog.Value
func LogValueAny(v any) slog.Value

or

func GoString[T ScalarType](v T) string
func GoString(v any) string

given that the representation is always a Go-code-like string? For example, int32(42) and int64(42).

cristaloleg commented 10 months ago

1st option will require bumping Go version in go.mod. 2nd looks much simpler :¯_(ツ)_/¯

AlekSi commented 7 months ago

After implementing it multiple times in multiple forms, I no longer think there is a good universal output format for BSON values. In some cases, you would want to preserve type information (for example, to output int32, int64, and float64 differently); sometimes, you don't (for example, to output all numbers as just numbers to make them indexable in the logs storage). It is use-case-specific and even handler-specific (text handler essentially removes all type information).

I think we could close that one.

cristaloleg commented 7 months ago

Fair enough. After all it's just a Go value. Closing.