simple library that provides compile-time or runtime set debug checks
Find a file
kim 93ef932263 make debug a constant exported variable
Signed-off-by: kim <grufwub@gmail.com>
2023-02-04 21:30:25 +00:00
debug.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_env.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_env_test.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_off.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_off_test.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_on.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
debug_on_test.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
go.mod first commit 2022-04-24 09:58:30 +01:00
LICENSE first commit 2022-04-24 09:58:30 +01:00
pprof_off.go add support for starting pprof server / wrapping pprof handler 2022-04-25 19:04:20 +01:00
pprof_off_test.go add support for starting pprof server / wrapping pprof handler 2022-04-25 19:04:20 +01:00
pprof_on.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
pprof_on_test.go make debug a constant exported variable 2023-02-04 21:30:25 +00:00
README.md first commit 2022-04-24 09:58:30 +01:00
run_tests.sh add support for starting pprof server / wrapping pprof handler 2022-04-25 19:04:20 +01:00

go-debug

This library provides a very simple method for compile-time or runtime determined debug checks, set using build tags.

The compile-time checks use Go constants, so when disabled your debug code will not be compiled.

The possible build tags are:

  • "debug" || "" = debug determined at compile-time

  • "debugenv" = debug determined at runtime using the $DEBUG environment variable

An example for how this works in practice can be seen by the following code:

func main() {
	println("debug.DEBUG() =", debug.DEBUG())
}
# Debug determined at compile-time, it is disabled
$ go run .
debug.DEBUG() = false

# Debug determined at compile-time, it is enabled
$ go run -tags=debug .
debug.DEBUG() = true

# Debug determined at runtime, $DEBUG is not set
$ go run -tags=debugenv .
debug.DEBUG() = false

# Debug determined at runtime, $DEBUG is set
$ DEBUG=y go run -tags=debugenv .
debug.DEBUG() = true