Like Rust's dbg macro, but for Go!
debug
provides a simple, elegant mechanism to streamline "print debugging", inspired by Rust's dbg macro
Warning
This is not intended for logging in production, more to enable quick local debugging while iterating. debug.Debug
should not make it into your production code
go get github.com/FollowTheProcess/debug@latest
package main
import "fmt"
func main() {
something := "hello"
fmt.Printf("something = %s\n", something)
}
something = something
- Not ideal, need to manually type variable name
- No source info, could easily get lost in a large program
- Need to deal with fmt verbs
package main
import "github.com/FollowTheProcess/debug"
func main() {
something := "hello"
debug.Debug(something)
}
DEBUG: [/Users/you/projects/myproject/main.go:7:3] something = "hello"
- Source info, yay! 🎉
- Variable name is handled for you
- Can handle any valid go expression or value
- No fmt print verbs
This package was created with copier and the FollowTheProcess/go_copier project template.