using runtime /debuglog.go

69 views
Skip to first unread message

Leah Stapleton

unread,
Aug 6, 2024, 9:10:34 AM8/6/24
to golang-nuts
I'm trying to debug a problem in the go runtime and wished to use the debuglog.go features found in https://github.com/golang/go/blob/master/src/runtime/debuglog.go

However,  when I follow the example here https://github.com/golang/go/issues/59600#issuecomment-1515040287 

d := dlog() if d != nil { d.s("foo") d.i(42) d.end() }

I can't build the Go source code

Building Go cmd/dist using /usr/local/go (go1.22.0 darwin/amd64)
Building Go toolchain1 using /usr/local/go
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1

Invalid operation d != nil mismatched types (dlogger and untyped nil)

I changed the code to remove the d != nil check, and was able to build the go source code, but when I build my app with this go source code using the -tags debuglog

bin/go build -tags debuglog -o myapp *.go

it is not printing any debug logs to my terminal

Can any suggest anything?

Thank you
  

invalid operation: d != nil (mismatched types dlogger and untyped nil)

Building Go cmd/dist using /usr/local/go. (go1.22.0 darwin/amd64)

Building Go toolchain1 using /usr/local/go.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.

Building Go cmd/dist using /usr/local/go. (go1.22.0 darwin/amd64)

Building Go toolchain1 using /usr/local/go.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.

Building Go cmd/dist using /usr/local/go. (go1.22.0 darwin/amd64)

Building Go toolchain1 using /usr/local/go.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.


Building Go cmd/dist using /usr/local/go. (go1.22.0 darwin/amd64)

Building Go toolchain1 using /usr/local/go.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.

Building Go cmd/dist using /usr/local/go. (go1.22.0 darwin/amd64)

Building Go toolchain1 using /usr/local/go.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.


 invalid operation: d != nil (mismatched types dlogger and untyped nil)

Rhys Hiltner

unread,
Aug 6, 2024, 6:24:54 PM8/6/24
to golang-nuts
The behavior of that nil check may have changed last week in https://github.com/golang/go/commit/548158c4a57580e8c8bd0e9b2f91d03b31efa879 . Maybe because dloggerFake is a struct{} rather than a *struct{}?

I wouldn't bother with the nil check. I'd chain the methods like dlog().s("foo").i(42).end() and never (or, nearly never) keep a reference to an active dlogger.

The debug logger doesn't print anything on normal exits—only when the program crashes. That's what Michael P meant in the issue update you linked by "The buffer will be dumped on throw." I'm not sure how severely the program has to crash in order to trigger that printing. It should definitely work with runtime.throw. Maybe also with a normal un-recovered panic, or possibly also with os.Exit(1).
Reply all
Reply to author
Forward
0 new messages