Skip to content

log/slog: text handler shows pointer address instead structures #68233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
greeddj opened this issue Jun 28, 2024 · 3 comments
Closed

log/slog: text handler shows pointer address instead structures #68233

greeddj opened this issue Jun 28, 2024 · 3 comments

Comments

@greeddj
Copy link

greeddj commented Jun 28, 2024

Go version

go version go1.22.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/das/Library/Caches/go-build'
GOENV='/Users/das/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/das/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/das/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/das/Develop/testing/slog_test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/09/mv8r2msx43l5t38mwljc2xfm0000gn/T/go-build3466276063=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Hi there!

I'm facing a problem displaying nested structures by pointer in a log/slog values with text handler.
With json handler pointers successfully expands to structures.

Here's a link to example code to reproduce the issue: https://go.dev/play/p/rGeaRdW1cG4

What did you see happen?

Here's a quick example of what I'm talking about

 {"time":"2009-11-10T23:00:00Z","level":"INFO","msg":"Json","Test2":{"Struct":{"Text":"I'm an inner struct link"}}}
time=2009-11-10T23:00:00.000Z level=INFO msg=Text Test2=&{Struct:0xc000102050}

What did you expect to see?

I expect to see the same behavior between the handlers.

 {"time":"2009-11-10T23:00:00Z","level":"INFO","msg":"Json","Test2":{"Struct":{"Text":"I'm an inner struct link"}}}
time=2009-11-10T23:00:00.000Z level=INFO msg=Text Test2=&{"Struct":&{"Text":"I'm an inner struct link"}}

or

time=2009-11-10T23:00:00.000Z level=INFO msg=Text Test2={"Struct":{"Text":"I'm an inner struct link"}}
@seankhliao
Copy link
Member

I believe this is working as intended:

From log/slog.TextHandler.Handle:

If a value implements encoding.TextMarshaler, the result of MarshalText is written. Otherwise, the result of fmt.Sprint is written.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@greeddj
Copy link
Author

greeddj commented Jun 28, 2024

Ok. Thx for info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants